Member-only story
UILocalNotification iOS
Local notifications allow your app to notify the user about content which does not require the use of a server.
Unlike remote notifications which are triggered from a server, local notifications are scheduled and triggered within an app. Notifications in general are targeted to increase user interaction with the app, inviting or tempting the user to open and interact with it.
UILocalNotification was deprecated in iOS 10. Use the UserNotifications framework instead.
Scheduling a local notification
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…