Remote notifications

Push notifications on iOS 8.

We upgraded to iOS 8 and XCode 6 and all was good until we noticed that push notifications stopped working. For some time we could not figure out what was going on but then we noticed the following NSLog message in the console: registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later

To make it work we had to update registerForRemoteNotificationTypes code to:

UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [application registerUserNotificationSettings:settings];
 } else {
    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];

And to add the following code in our AppDelegate:

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings<br/>{<br/>    //register to receive notifications<br/>    [application registerForRemoteNotifications];<br/>}

note: #ifdef __IPHONE_8_0 is only needed if at some point we want to compile for old iOS SDKs.

Subscribe to The infinite monkey theorem

Get the latest posts delivered right to your inbox