DidRegisterForRemoteNotificationsWithDeviceToken not called in ios 9

I need to implement APNS in my project, I created APNS SSL in the developers portal, and with this I created a new position profile for this. Using an SSL certificate, I created a P12 file and then combined it with a PEM file. I get a pop-up that the application wants to send you a notification ..... I accept this, but still I have not received the device token.

In didfinishLaunching I use this part

 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]); } } 
+4
ios objective-c iphone objective-c-blocks
Nov 05 '15 at 9:47
source share
3 answers

Try it out.

 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)]; } 
+9
Nov 05 '15 at 9:57
source share

I think you forgot your didRegisterUserNotificationSettings method to:

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

in the same place also check the following scenario.

  • try again on another device
+4
Nov 05 '15 at
source share

in ios 9, you only need if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; }

other changes:

  • select Project-> General Recruitment Team
  • Go and turn on the push notification. enter image description here
+1
04 Oct '16 at 10:25
source share



All Articles