iOS UILocalNotification Scheduling a local notification

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

Make sure you see Registering for local notifications in order for this to work:

Swift

let notification = UILocalNotification()
notification.alertBody = "Hello, local notifications!"
notification.fireDate = NSDate().dateByAddingTimeInterval(10) // 10 seconds after now
UIApplication.sharedApplication().scheduleLocalNotification(notification)

Objective-C

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = @"Hello, local notifications!";
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10]; // 10 seconds after now
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

To see the notification in the iOS Simulator, type ^⌘H (control-command-H) to go home and then type ⌘L (command-L) to lock the device. Wait a few seconds, and the notification should appear (this appearance will vary depending on notification type discussed in "Registering for local notifications"):

Local Notification Banner

Swipe on the notification to get back to the app (note that if you called this in the first view controller's viewDidLoad, viewWillAppear, viewDidAppear, etc., the notification will be scheduled again).



Got any iOS Question?