didReceiveRemoteNotification不工作ios9

时间:2016-02-23 07:29:24

标签: ios apple-push-notifications

我按照这些步骤进行推送通知,但无法接收推送设备。

步骤

  1. 在我的项目中制作和添加推送应用ID和配置文件
  2. 在我的项目中启用推送通知
  3. 制作p12文件和.pem文件
  4. 将.pem文件发送给php developer
  5. 在我的app delegate.m
  6. 中使用以下代码

    代码:

    Array
    (
        [0] => Array
            (
                [email] => abc@gmail.com
                [id] => Array
                    (
                        [0] => 1
                        [1] => 2
                        [2] => 3
                    )
    
            )
    
    )
    

2 个答案:

答案 0 :(得分:0)

注册用户通知设置后,您需要通过调用此方法[[UIApplication sharedApplication] registerForRemoteNotifications]来注册远程通知。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //ios 9
    UIUserNotificationType types = UIUserNotificationTypeBadge |
    UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

    UIUserNotificationSettings *mySettings =
    [UIUserNotificationSettings settingsForTypes:types categories:nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

   //call this method here
   [[UIApplication sharedApplication] registerForRemoteNotifications];

    return YES; 
}

答案 1 :(得分:0)

在AppDelegate.m的didFinishLaunchingWithOptions中添加以下代码:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }

为我的iOS 9.0和Xcode 7.2工作。