17.4. Scheduling Local Notifications


You are developing an app, such as an alarm clock or a calendar app, that needs to inform the user of an event at a specific time, even if your app is not running or is in the background.


Instantiate an object of type UILocalNotification, configure it (we will see how), and schedule it using the scheduleLocalNotification: instance method of the UIApplication class. You can get the instance of your application object using the sharedApplication class method of the UIApplication class.


A local notification is what gets presented to the user if your application is running in the background or not running at all. You can schedule the delivery of a local notification using the scheduleLocalNotification: instance method of UIApplication. If your app is running in the foreground and a scheduled local notification is fired, no alert is displayed to the user. Instead, iOS will silently, through an app delegate message, let you know that the notification was fired. Don’t worry about this for now; we will go into details about all this quite soon.

You can ask iOS to deliver a local notification to the user in the future when your application is not even running. These notifications could also be recurring—for instance, every week at a certain time. However, extra care must be taken when you are specifying the fire date for your notifications.

The cancelAllLocalNotifications instance method cancels the delivery of all pending local notifications ...

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.