【问题标题】:Push notification not receiving in iOS 10在 iOS 10 中未收到推送通知
【发布时间】:2017-01-23 01:55:11
【问题描述】:

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

我担心这会影响所有用户还是只影响我自己。任何人找到合适的解决方案,请告诉我。

提前致谢

【问题讨论】:

标签: ios push-notification apple-push-notifications ios10


【解决方案1】:

需要对带有 xCode 8 GM 的 iOS 10 进行一些更改 您需要实现 UserNotifications.framework 及其委托方法来获得推送通知的工作。

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

【讨论】:

  • 面临同样的问题。因此,我使用适用于 iOS 10 的 xCode 8 GM 将我的应用程序重新提交到 Appstore。
  • @AshishShah 无需实现UserNotification。仍然可以使用UIUserNotificationSettings 完成。您只需要启用推送通知功能,这将在您的项目中创建一个.entitlement 文件。
  • 我同意@Ra
【解决方案2】:

UserNotifications”在 iOS10 中不是强制性的。 “UIUserNotificationSettings”在 iOS10 中仍然有效。

如果你有以下代码,应该可以在iOS10上运行。

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

但如果您使用 Xcode8 及更高版本进行构建,请确保您的 权利 中有以下条目。在“Capabilities”中启用“Push Notifications”后,该条目将自动添加。

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

在发布分发版本中,这将自动更改为 关注

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

【讨论】:

    【解决方案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
        }
    }
    

    Handel 委托方法

    //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 上使用相同的UIUserNotification。唯一的区别是在 Capabilities 中添加 Push Notifications 权利
    【解决方案4】:

    在 iOS 10 上必须添加推送通知权利,因此如果您在 Capabilities 中“修复问题”,问题将自动解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多