Sapan Diwakar

Software developer

Follow me on Twitter Check out my code on GitHub View some of my designs on Dribbble Take a look at my Linked In profile

Push Notifications in iOS8

Push notification iOS

There have been some great changes to iOS notifications with the iOS8 update. This means that now you can send a payload of upto 2KB instead of the 256 bytes earlier. iOS8 also separates the silent and UI push notifications. It means that you can send notifications without any UI (e.g. to update some data on your app) and this is accepted by default without having to ask for permissions from the user.

But, it also changes the way you register for push notifications presented on the UI. So instead of

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert |
                                                                      UIRemoteNotificationTypeBadge |
                                                                      UIRemoteNotificationTypeSound];

you should be using the following to register for notifications now.

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

By the way, that's not all. You can even give categories to allow actionable push notifications. Check out the documentation for UIUserNotificationSettings for complete details or watch the What's new in Notifications video from WWDC.