简体   繁体   English

推送通知已停止适用于IOS 8

[英]Push notification stopped working for IOS 8

I have my application signed using enterprise certificate which supports push notification feature in it. 我使用支持推送通知功能的企业证书对应用程序进行了签名。 It was working fine and when I updated iphone to iOS 8 push notification stopped working. 一切正常,当我将iPhone更新为iOS 8时,推送通知停止工作。 After I debug and little research I came to know that following code to be added to retrieve push token from iOS 8 onwards. 经过调试和很少的研究之后,我知道要添加以下代码来从iOS 8开始检索推送令牌。

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) //>iOS8
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}else {// <iOS8
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

}

Add following callback methods,

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
     [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
    //handle the actions
}

However we do not face this problem with appstore version of our application and all working good. 但是,我们的应用程序的Appstore版本不会遇到此问题,并且一切正常。 Is it something broken on enterprise certification only? 仅在企业认证上有问题吗?

You are forgeting a line code: [[UIApplication sharedApplication] registerForRemoteNotifications]; [[UIApplication sharedApplication] registerForRemoteNotifications];了一个行代码: [[UIApplication sharedApplication] registerForRemoteNotifications];

something like this: 像这样的东西:

if ([application respondsToSelector: selector (registerUserNotificationSettings :)]) {
      UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound
                                                                               categories: nil ];
       [[UIApplication sharedApplication] registerUserNotificationSettings: settings];
       [[UIApplication sharedApplication] registerForRemoteNotifications];
   } else {
       [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        UIRemoteNotificationTypeBadge |
        UIRemoteNotificationTypeAlert |
        UIRemoteNotificationTypeSound];

   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM