推送通知不在iOS 10中收到

我的应用程序在Appstore中。 推送通知在iOS 9中工作正常,但在iOS 10中不起作用。 我没有收到iOS 10设备的任何推送通知。 我检查了服务器中的设备令牌和证书。 全部正确。 我也检查了设置应用程序中的通知属性。 一切都很好。 但是我没有收到任何通知。 我只是closures和打开我的应用程序的通知。 我打开我的应用程序来检查设备令牌是否正在更改。 它被更改并更新到我的服务器。 然后我正确地收到通知。 现在对我的设备工作正常。

我担心这是否会影响所有用户或只有我。 任何人find正确的解决scheme,请让我知道。

提前致谢

使用xCode 8 GM需要对iOS 10进行一些更改您需要实现UserNotification.framework及其委托方法以获取推送通知的工作。

我用新的UserNotification.framework解决了我的问题。 请点击以下链接: 推送iOS 10的通知问题

“用户通知 ”在iOS10中不是强制性的。 “ UIUserNotificationSettings ”仍然适用于iOS10。

如果你有下面的代码,它应该在iOS10中工作。

 [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 

但是,如果您使用Xcode8及更高版本构build, 确保在您的权利中包含以下条目。 一旦您在“ function ”中启用“推送通知”,该条目将自动添加。

 <key>aps-environment</key> <string>development</string> 

在发布版本构build中,这将自动更改为以下内容

 <key>aps-environment</key> <string>production</string> 

我们需要更改iOS 10的一些代码。

Appdelegate.h

 #import <UserNotifications/UserNotifications.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate> @end 

检查操作系统版本

 #define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 

注册通知

 - (void)registerForRemoteNotifications { if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if(!error){ [[UIApplication sharedApplication] registerForRemoteNotifications]; } }]; } else { // Code for old versions } } 

亨德尔委托方法

 //foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ NSLog(@"User Info : %@",notification.request.content.userInfo); completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); } -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ NSLog(@"User Info : %@",response.notification.request.content.userInfo); completionHandler(); } 

在iOS 10上有必要添加推送通知授权,所以如果您在function“修复问题”,问题将自动解决。