11. Creating a Notification
• User performs an action.
• Create a
UILocalNotification
instance & configure it.
12. Creating a Notification
• User performs an action.
• Create a
UILocalNotification
instance & configure it.
• Register the notification
with the UIApplication
instance.
13. Creating a Notification
• User performs an action.
• Create a
UILocalNotification
instance & configure it.
• Register the notification
with the UIApplication
instance.
14. Creating a Notification
• User performs an action.
• Create a
UILocalNotification
instance & configure it.
• Register the notification
with the UIApplication
instance.
15. Creating a Notification
• User performs an action.
• Create a
UILocalNotification
instance & configure it.
• Register the notification
with the UIApplication
instance.
18. Receiving a Notification
• Some time passes…
• If the device is locked,
then we receive the
notification bubble.
19. Receiving a Notification
• Some time passes…
• If the device is locked,
then we receive the
notification bubble.
• If the user acknowledges
this, the application
activates and responds
to the notification.
20. Receiving a Notification
• Some time passes…
• If the device is locked,
then we receive the
notification bubble.
• If the user acknowledges
this, the application
activates and responds
to the notification.
22. Receiving a Notification
• If the device is active
and the application is
not running, the
notification bubble will
appear.
23. Receiving a Notification
• If the device is active
and the application is
not running, the
notification bubble will
appear.
• If the user responds to
this, the application will
activate & respond
24. Receiving a Notification
• If the device is active
and the application is
not running, the
notification bubble will
appear.
• If the user responds to
this, the application will
activate & respond
26. Receiving a Notification
• If the application is in the foreground,
then no notification is presented.
27. Receiving a Notification
• If the application is in the foreground,
then no notification is presented.
• The application will receive a message on
the delegate and able to take over.
30. Creating a Notification
• Alloc/init a UILocalNotification
instance.
• Configure its properties.
• Register with the application’s
UIApplication instance.
51. Scheduling
• Get the UIApplication instance and call
scheduleLocalNotification:
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
55. Cancelling Notifications
• To cancel a single notification:
• Call cancelLocalNotification:
• To cancel all notifications:
• Call cancelAllLocalNotifications
66. Other Resources
• “Local and Push Notification Programming
Guide” - developer.apple.com/iphone
• “Session 129 - Implementing Local and
Push Notifications” - WWDC 2010 videos
Editor's Notes
- OS3 introduced push notifications - allowing an external server to push to your phone.
- Required you to maintain external infrastructure (and was complicated!)
- Local notifications allow you to generate notifications without relying upon the external infrastructure
- One of Steve’s tentpole’s with iOS 4
- Badges: Increment/Decrement the icon’s badge (on the Springboard)
- Sounds: Play an alert tone when the notification is fired
- Alerts: Display a message on screen
- Badges: Increment/Decrement the icon’s badge (on the Springboard)
- Sounds: Play an alert tone when the notification is fired
- Alerts: Display a message on screen
- Badges: Increment/Decrement the icon’s badge (on the Springboard)
- Sounds: Play an alert tone when the notification is fired
- Alerts: Display a message on screen
- Badges: Increment/Decrement the icon’s badge (on the Springboard)
- Sounds: Play an alert tone when the notification is fired
- Alerts: Display a message on screen
- the basic notification lifecycle for the user (in case no one has seen these in action)
- Create the notification
- Set the details
- Register with the UIApplication instance.
- Create the notification
- Set the details
- Register with the UIApplication instance.
- Create the notification
- Set the details
- Register with the UIApplication instance.
- Create the notification
- Set the details
- Register with the UIApplication instance.
- Create the notification
- Set the details
- Register with the UIApplication instance.
- Create the notification
- Set the details
- Register with the UIApplication instance.
- Notification will appear on the lock screen (with the Slide to View) text.
-
- Notification will appear on the lock screen (with the Slide to View) text.
-
- Notification will appear on the lock screen (with the Slide to View) text.
-
- Notification will appear on the lock screen (with the Slide to View) text.
-
- That is, you’re looking at the application, right as the notification is fired!
- That is, you’re looking at the application, right as the notification is fired!
- EB Sample code (with modifications for clarity).
- We create a dictionary for User Info (we populate this in the actual code, but leaving it empty here).
-
- fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification.
- timeZone: Defines the timeZone the notification should be scheduled in. Can be left at nil - treats the date as a GMT time. Otherwise, treats will update the time based on the timezone.
- repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year)
- repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications.
- fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification.
- timeZone: Defines the timeZone the notification should be scheduled in. Can be left at nil - treats the date as a GMT time. Otherwise, treats will update the time based on the timezone.
- repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year)
- repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications.
- fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification.
- timeZone: Defines the timeZone the notification should be scheduled in. Can be left at nil - treats the date as a GMT time. Otherwise, treats will update the time based on the timezone.
- repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year)
- repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications.
- fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification.
- timeZone: Defines the timeZone the notification should be scheduled in. Can be left at nil - treats the date as a GMT time. Otherwise, treats will update the time based on the timezone.
- repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year)
- repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications.
- fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification.
- timeZone: Defines the timeZone the notification should be scheduled in. Can be left at nil - treats the date as a GMT time. Otherwise, treats will update the time based on the timezone.
- repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year)
- repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications.
- alertBody: Defines the message which will appear in the alert bubble.
- hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to
NO, requires alertBody to have a value!
- alertAction: Title of the Slider/Action button on the pop-up
- alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched.
- alertBody: Defines the message which will appear in the alert bubble.
- hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to
NO, requires alertBody to have a value!
- alertAction: Title of the Slider/Action button on the pop-up
- alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched.
- alertBody: Defines the message which will appear in the alert bubble.
- hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to
NO, requires alertBody to have a value!
- alertAction: Title of the Slider/Action button on the pop-up
- alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched.
- alertBody: Defines the message which will appear in the alert bubble.
- hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to
NO, requires alertBody to have a value!
- alertAction: Title of the Slider/Action button on the pop-up
- alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched.
- alertBody: Defines the message which will appear in the alert bubble.
- hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to
NO, requires alertBody to have a value!
- alertAction: Title of the Slider/Action button on the pop-up
- alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched.
applicationIconBadgeNumber: what count appears on the application’s badge
soundName: Filename to a sound file in the application bundle (needs to be <30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info).
userInfo: Dictionary containing application specific details. Must be valid property list types.
applicationIconBadgeNumber: what count appears on the application&#x2019;s badge
soundName: Filename to a sound file in the application bundle (needs to be <30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info).
userInfo: Dictionary containing application specific details. Must be valid property list types.
applicationIconBadgeNumber: what count appears on the application&#x2019;s badge
soundName: Filename to a sound file in the application bundle (needs to be <30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info).
userInfo: Dictionary containing application specific details. Must be valid property list types.
applicationIconBadgeNumber: what count appears on the application&#x2019;s badge
soundName: Filename to a sound file in the application bundle (needs to be <30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info).
userInfo: Dictionary containing application specific details. Must be valid property list types.
- Returns an Array of the pending notifications for your application (those which haven&#x2019;t yet fired).
- Any notifications which you submitted & have been fired are lost - that may mean you need to cache notifications independently.
- UILocalNotification objects are NSCoding compliant, so they can be serialised out.
- Call cancelLocalNotification: with the UILocalNotification instance you wish to remove.
- Call cancelLocalNotification: with the UILocalNotification instance you wish to remove.
Not running? We then enter the application:didFinishLaunchingWithOptions: method in our app delegate.
Check the launchOptions dictionary for the presence of UIApplicationLaunchOptionsLocalNotificationKey.
If present, the associated value is a UILocalNotification object, which we can then process.
Not running? We then enter the application:didFinishLaunchingWithOptions: method in our app delegate.
Check the launchOptions dictionary for the presence of UIApplicationLaunchOptionsLocalNotificationKey.
If present, the associated value is a UILocalNotification object, which we can then process.
- is the replacement for applicationDidFinishLaunching: delegate method (added in iOS 3)
- Delegate&#x2019;s application:didReceiveLocalNotification: method with the UILocalNotification instance
- calling [application applicationState] lets us know if we&#x2019;re Active (meaning in foreground), Background (was running in background), or Inactive.
- I used this check so I could emulate the notification alertview (as I didn&#x2019;t want my app to automatically respond).
- Depending on your own app, you may want it to respond automatically.