我已经集成了Push通知,我能够在iOS 11.2,iOS 11.3等版本上获得Push通知令牌。但是无法在iOS 11.4.1版本上接收设备令牌。
方法didRegisterForRemoteNotificationsWithDeviceToken
和didFailToRegisterForRemoteNotificationsWithError
没有被调用。
有人面对这个问题吗?我要检查此设备问题还是iOS版本问题?
答案 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)
}
}