无法在iOS 11.4.1上获得推送通知的令牌

时间:2018-08-29 10:25:14

标签: ios push-notification

我已经集成了Push通知,我能够在iOS 11.2,iOS 11.3等版本上获得Push通知令牌。但是无法在iOS 11.4.1版本上接收设备令牌。

方法didRegisterForRemoteNotificationsWithDeviceTokendidFailToRegisterForRemoteNotificationsWithError没有被调用。

有人面对这个问题吗?我要检查此设备问题还是iOS版本问题?

1 个答案:

答案 0 :(得分:0)

您能像通常在Appdelegate didFinishLaunchingWithOptions

中请求权限吗?
 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)

     }
}