O'Reilly logo

iOS 7 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.4. Scheduling Local Notifications

Problem

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.

Solution

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.

Discussion

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required