Notifications in iOS 8

Guides | Tutorial By 3 years ago

In iOS 8 the notification behavour has changed.

Previously an app could send a user a local notification without their initial permission, but would need to get their permission if the user was to get notifications sent remotely as a push notification.

As of iOS 8 all notifications need to get user permission. Whether it’s local or push, your app now needs to present that user alert when wanting to deal with notifications.

Here’s what the OLD code would have looked like, note this was only if you wanted to do remote notifications

UIApplication* application = [UIApplication sharedApplication];
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

Here’s what apps now need to do:

UIApplication* application = [UIApplication sharedApplication];

if([application respondsToSelector:@selector(registerUserNotificationSettings:)])
	[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge  | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]];
	[application registerForRemoteNotifications];

The best thing to come out of this is now you can get that “wants to send you notifications” alert on the simulator, making it much easier to test different notification scenarios 🙂