ios - iOS 12 推送通知在以下版本中不起作用,在 iOS 12 中未收到推送通知
问题描述
对于 iOS 12 推送通知无法正常工作并在以下版本中工作
我的应用在 Appstore 中。推送通知在 iOS 11 中运行良好,但在 iOS 12 中无法正常工作。我没有收到 iOS 12 设备的任何推送通知。我已经检查了我的服务器中的设备令牌和证书。全部正确。我还检查了设置应用程序中的通知属性。一切都很好。但是我没有收到任何通知。
这是我用于推送通知的代码。
你能建议我会是什么问题。如何解决这个问题?
func registerForPushNotifications() {
if #available(iOS 10.0, *){
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
if (granted)
{
UIApplication.shared.registerForRemoteNotifications()
}
else{
//Do stuff if unsuccessful...
UIApplication.shared.registerForRemoteNotifications()
}
// Enable or disable features based on authorization.
}
}
else
{
let types: UIUserNotificationType = [UIUserNotificationType.badge, UIUserNotificationType.alert, UIUserNotificationType.sound]
let settings: UIUserNotificationSettings = UIUserNotificationSettings( types: types, categories: nil )
UIApplication.shared.registerUserNotificationSettings( settings )
UIApplication.shared.registerForRemoteNotifications()
}
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo as NSDictionary
print(userInfo)
}
解决方案
当我的应用程序在“调试”中运行时我遇到了同样的问题,
我在“发布”中运行应用程序并且通知工作正常
推荐阅读
- c - SIMD 搜索最后一个峰值后的低谷
- reactjs - 将多个属性传递给组件
- javascript - 我想在javascript中捕获选中复选框的所有标签
- java - 意外的 Java Maven 项目命名
- h2 - Ontop 无法导入映射
- visual-studio - 不要在 monaco 评论中渲染图像预览
- android - 如何从片段重定向到下一页
- javascript - 如何在 React 中创建使用状态和道具的可重用函数
- amazon-web-services - 如何离线使用 AWS SAM CLI 本地 HttpAPI 和 JWT Bearer 令牌认证?
- pine-script - Pine Editor:如何将非标准指标中的值调用到脚本中