2015-11-05 69 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