iOS 12推送通知无法正常工作,而在以下版本中可以正常工作。
我的应用已经发布在Appstore上。在iOS 11上,推送通知可以正常工作,但是在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)
}