2016-09-15 64 views
6

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

我担心这是否会影响所有用户或只有我。任何人都可以找到合适的解决方案,请告诉我

在此先感谢

+0

尝试这种类型的代码:http://stackoverflow.com/questions/39382852/didreceiveremotenotification-not-called- ios-10/39383027#39383027 –

+0

我检查了以前的解决方案。但我的应用没有iOS 10 SDK。那么它应该如何影响iOS 10。 –

+0

您正在下载或升级您的xcode 8可能会升级xcode。 –

回答

7

需要在Xcode 8 GM 您需要实现UserNotification.framework和他们的代表的方法来获取推送通知的工作的一些变化对iOS的10。

我已使用新的UserNotification.framework解决了我的问题。 请点击此链接:Push notification issue with iOS 10

+0

但它不适用于已经在AppStore中的Apps。 –

+0

面临同样的问题。所以我已经使用xCode 8 GM for iOS 10将我的应用程序重新提交给Appstore。 –

+0

@AshishShah无需实施'UserNotification'。它仍然可以通过'UIUserNotificationSettings'完成。您只需启用推送通知的功能,即可在您的项目中创建一个'.entitlement'文件。 –

3

我们需要改变一些代码为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(); 
} 
+1

不需要,我们仍然可以在iOS 10中使用相同的'UIUserNotification'。唯一的区别是在功能中添加推送通知权利 –

1

在iOS上10是根据需要添加推送通知的权利,所以如果你在能力问题会自动解决“解决问题”。

5

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

如果您有以下代码,它应该在iOS10中工作。

[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 

但如果你用Xcode8及以上的建设,可以确保你有你的权利以下条目。当您在“功能”中启用“推送通知”后,此条目将自动添加。

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

在释放分布构建这将自动更改为 以下

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