【问题标题】:Not getting token for Push notification on iOS 11.4.1在 iOS 11.4.1 上未获得推送通知的令牌
【发布时间】:2018-08-29 10:25:13
【问题描述】:

我已经集成了推送通知,我可以在 iOS 11.2、iOS 11.3 等版本上获取推送通知令牌。但在 iOS 11.4.1 版本上无法接收设备令牌。

方法didRegisterForRemoteNotificationsWithDeviceTokendidFailToRegisterForRemoteNotificationsWithError 没有被调用。

有人遇到这个问题吗?我想检查是这个设备问题还是iOS版本问题?

【问题讨论】:

  • 您是否向用户请求了权限?您是否有正确的权利设置?应用是否(由用户)授权?
  • 是的,用户通过使用 API 获得授权:UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in print("granted: ((授予)") };

标签: ios push-notification


【解决方案1】:

您能否在AppdelegatedidFinishLaunchingWithOptions 中请求权限

 if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self
    } else {
        // Fallback on earlier versions
    }
    if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) {(accepted, error) in
            if !accepted {
                print("Notification access denied.")
            }
        }
        UIApplication.shared.registerForRemoteNotifications()
    } else {
        // Fallback on earlier versions
    }

然后请尝试使用

检索令牌
 extension AppDelegate: UNUserNotificationCenterDelegate {

        func application(_ application: UIApplication, 
       didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
               let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
               print(token)

     }
}

【讨论】:

  • 是的,在我的代码中完成了相同的实现。而且我也收到了 iOS 11.3 版本的推送通知令牌。我想知道 iOS 11.4.1。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-26
  • 2018-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多