2015-11-05 67 views
4

我叫了起来实现APNS在我的项目,我已经创建APNSSSL在开发人员门户网站,并使用这个这个,我已经创造新规定的个人资料。 使用SSL证书我创建P12文件,然后合并它PEM文件。 我收到弹出窗口,应用程序想向您发送通知..... 我接受,但我仍然没有得到设备令牌!didRegisterForRemoteNotificationsWithDeviceToken没有在IOS 9

didfinishLaunching我用这部分

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

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

      [[UIApplication sharedApplication] registerForRemoteNotifications]; 

      //[[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]; 
    } 


I have used delegate method of push notification 


- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error 
{ 
    NSLog(@"Failed to get token, error: %@", error); 
} 


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 

    for (id key in userInfo) { 
     NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]); 
    }  

} 
+0

您是否正在使用APNS证书在设备上安装生成? – Rushabh

+0

是与APNS证书我创建了提供个人资料,并使用该身材,我使用IPA文件 –

回答

9

试着用这一个。

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){ 

    UIUserNotificationType types = UIUserNotificationTypeBadge | 
    UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 

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

    [application registerUserNotificationSettings:mySettings]; 
    [application registerForRemoteNotifications]; 


}else{ 
    [application registerForRemoteNotificationTypes: 
    (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; 
} 
+0

TNX这对我的作品 –

4

我想你忘记你的didRegisterUserNotificationSettings方法,以便:

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { 
    if (notificationSettings.types != UIUserNotificationTypeNone) { 
     NSLog(@"didRegisterUser is called"); 
     [application registerForRemoteNotifications]; 
    } 
} 

在同一个地方检查以下情形也。

  • 尝试在其他设备一旦
+0

我已经补充说,但仍然没有得到设备令牌 –

+0

是你在其他设备试图 –

1
在IOS

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

的其他变化是

  1. 选择项目 - >常规设置
  2. 去功能并打开推通知。 enter image description here