推送通知在iOS 9中无效

时间:2015-09-22 13:30:59

标签: push-notification apple-push-notifications ios9 xcode7

我已将设备升级到iOS 9,将Xcode环境升级到7.0 公测。推送通知在iOS 9中无效?

这是我的代码:

  float ver = [[[UIDevice currentDevice] systemVersion] floatValue];

    if(ver >= 8 && ver<9)
    {
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
        {
            [[UIApplication sharedApplication] registerForRemoteNotifications];
            UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

        }
    }else if (ver >=9){

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];


    }
    else{
        //iOS6 and iOS7 specific code
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert];
    }

推送通知在使用Xcode 6.4构建的iOS 8到8.3上正常工作。

5 个答案:

答案 0 :(得分:5)

在项目中添加code并创建证书和Ad-Hoc个人资料后 -

<强> *Just enable this from your X-code*

enter image description here

了解更多详情 - iOS 9 Push Notification Tutoriyal

答案 1 :(得分:-1)

我遇到了同样的问题。我通过创建 Ad-Hoc配置文件解决了这个问题。当我使用开发配置文件时,我注意到没有发生推送。我注意到的另一件事是每次全新安装都会更改设备令牌,这有点奇怪,因为我们必须为每个新实例更新服务器。

您可以阅读本文以便更好地理解: iOS 9 Push Notifications

答案 2 :(得分:-2)

在didFinishLaunchingWithOptions

中编写此代码
 UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                         categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

并将此方法添加到AppDelegate,因为我已经用于解析推送通知服务

 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  // Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
}

答案 3 :(得分:-2)

请尝试将此代码用作我的IOS 9应用程序

在AppDelegate中编写代码DidFinishLaunchWithOption

if([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:  [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];

    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
   #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |    UIUserNotificationTypeSound)]; #endif
}

确保为服务器上的推送通知检查了以下项目

  1. 选择Cert&amp ;;生成的PEM文件来自发起人的私钥
  2. 启用Apple服务并正确指向Sandbox / Live
  3. 在下面的函数中收到了推送通知令牌,并且没有返回任何错误,该错误很好地发送到正在向设备令牌发送APNS推送通知的服务器(LAMP服务)。
  4. 使用Push send to the token检查服务器中的Apple APNS响应代码。
  5. 在设置中启用了推送通知,就像在&#39; |&#39;中进行了任何搞砸一样。符号代码您可能会看到Apple常规通知设置中未显示的声音,徽章选项

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
        {
            NSString *devicetokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; 
    
            DLog(@"Did Register for Remote Notifications with Device Token DATA (%@) \n STRING token (%@)", deviceToken,devicetokenString);
    
            //If Same token received again dont take any action else save in NSUserdefaults or system and send to server to register against this device to send push notification on the token specified here.
        }
    
    -(void)application:(UIApplication *)application    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error 
        {
            DLog(@"Did Fail to Register for Remote Notifications");
            DLog(@"%s:%@, %@",__PRETTY_FUNCTION__,error, error.localizedDescription);
        }
    
    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
        {
            DLog(@"Did Receive for Remote Notifications with UserInfo:%@", userInfo);
        }
    
  6. 希望如果有任何帮助发布您的更新代码以便我们为您提供帮助,我们会很好地解释这一点。

答案 4 :(得分:-2)

如果您使用Diawi作为安装应用程序,而不是在IOS 9中使用的推送通知..

您通过Xcode安装应用程序..