对于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)
}
答案 0 :(得分:2)
我的应用程序在“调试”中运行时,我遇到了同样的问题,
我在“发行版”中运行应用,并且通知运行正常