iOS UILocalNotification Registering for local notifications

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any iOS Question?