iOS UILocalNotification Registering for local notifications


Example

iOS 8

In order to present local notifications to the user, you have to register your app with the device:

Swift

let settings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)

Objective-C

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

This will present an alert the first time it is called:

Register for local notifications alert

Regardless of what the user chooses, the alert will not show up again and changes will have to be initiated by the user in Settings.