Why is the application not registering for push notifications in iOS 8?

I upgraded my Xcode to Xcode 6.0.1, now for the iOS 8 device there is no registration of deleted notifications. It works great for an iOS 7 device.

I added the code to the application delegate as follows:

//-- Set Notification if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; NSLog(@"current notifications : %@", [[UIApplication sharedApplication] currentUserNotificationSettings]); } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; } 

Even the current notification is present, and it is not equal to zero.

And yet, the method below is not called:

 - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken 

The screenshot below explains that I turned on some options in the background:

enter image description here

And the notification is set in the device settings for my application.

+8
objective-c iphone ios8 xcode6 apple-push-notifications
source share
3 answers

You need to call

 [[UIApplication sharedApplication] registerForRemoteNotifications]; 

in your iOS8 code code after registering custom notification settings.

+16
source share

Below code will work in iOS 8.0 Xcode 6.0 or later, as well as for versions below.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //This code will work in iOS 8.0 xcode 6.0 or later if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; } return YES; } 
+13
source share

Check out the following steps, hope this helps you

Steps 1 In didFinishLaunchingWithOptions

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { //ios8 ++ if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; } } else { // ios7 if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotificationTypes:)]) { [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; } } 

Step 2

  -(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings // available in iOS8 { [application registerForRemoteNotifications]; } -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString * token = [NSString stringWithFormat:@"%@", deviceToken]; //Format token as you need: token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; token = [token stringByReplacingOccurrencesOfString:@">" withString:@""]; token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""]; NSLog(@"%@",token); } -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { // Handle your remote RemoteNotification } -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Error:%@",error); } 
+5
source share

All Articles