0

NOTE: This was apparently due to some sort of corruption in the Settings, the code was apparently fine all along...


Following the conversation in this thread: Remote Notification iOS 8, I added this boilerplate code to my app:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIRemoteNotificationTypeBadge categories:nil]];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
}
if ([[inLaunchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey]) {
    [appTracking registerPush:[inLaunchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}

I also added the application:didRegisterUserNotificationSettings handler, which calls a single line of code, [application registerForRemoteNotifications]. This code is called when the app starts.

Reading that thread, it is suggested that this is all that is required, and that this will cause application:didRegisterForRemoteNotificationsWithDeviceToken to be called. But that is definitely not happening in my app.

Did I miss a step, or simply mis-understand how to set this up?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98

2 Answers2

0

you need to add the following line [application registerForRemoteNotifications] after [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert]; iOS 8 condition

Good Luck

Mustafa Ibrahim
  • 1,110
  • 1
  • 9
  • 17
0

Try This :

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                             categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
} else {
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                     UIRemoteNotificationTypeAlert |
                                                     UIRemoteNotificationTypeSound)];
}
NSSakly
  • 209
  • 2
  • 11