• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Local Notifications @ Melbourne Cocoaheads (Aug 10)
 

Local Notifications @ Melbourne Cocoaheads (Aug 10)

on

  • 3,273 views

 

Statistics

Views

Total Views
3,273
Views on SlideShare
3,273
Embed Views
0

Actions

Likes
2
Downloads
42
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • - OS3 introduced push notifications - allowing an external server to push to your phone. <br /> - Required you to maintain external infrastructure (and was complicated!) <br /> - Local notifications allow you to generate notifications without relying upon the external infrastructure <br /> - One of Steve&#x2019;s tentpole&#x2019;s with iOS 4 <br />
  • - Badges: Increment/Decrement the icon&#x2019;s badge (on the Springboard) <br /> - Sounds: Play an alert tone when the notification is fired <br /> - Alerts: Display a message on screen <br />
  • - Badges: Increment/Decrement the icon&#x2019;s badge (on the Springboard) <br /> - Sounds: Play an alert tone when the notification is fired <br /> - Alerts: Display a message on screen <br />
  • - Badges: Increment/Decrement the icon&#x2019;s badge (on the Springboard) <br /> - Sounds: Play an alert tone when the notification is fired <br /> - Alerts: Display a message on screen <br />
  • - Badges: Increment/Decrement the icon&#x2019;s badge (on the Springboard) <br /> - Sounds: Play an alert tone when the notification is fired <br /> - Alerts: Display a message on screen <br />
  • - the basic notification lifecycle for the user (in case no one has seen these in action) <br /> <br />
  • - Create the notification <br /> - Set the details <br /> - Register with the UIApplication instance. <br />
  • - Create the notification <br /> - Set the details <br /> - Register with the UIApplication instance. <br />
  • - Create the notification <br /> - Set the details <br /> - Register with the UIApplication instance. <br />
  • - Create the notification <br /> - Set the details <br /> - Register with the UIApplication instance. <br />
  • - Create the notification <br /> - Set the details <br /> - Register with the UIApplication instance. <br />
  • - Create the notification <br /> - Set the details <br /> - Register with the UIApplication instance. <br />
  • - Notification will appear on the lock screen (with the Slide to View) text. <br /> - <br />
  • - Notification will appear on the lock screen (with the Slide to View) text. <br /> - <br />
  • - Notification will appear on the lock screen (with the Slide to View) text. <br /> - <br />
  • - Notification will appear on the lock screen (with the Slide to View) text. <br /> - <br />
  • <br /> <br />
  • <br /> <br />
  • <br /> <br />
  • - That is, you&#x2019;re looking at the application, right as the notification is fired! <br />
  • - That is, you&#x2019;re looking at the application, right as the notification is fired! <br />
  • <br />
  • <br />
  • - EB Sample code (with modifications for clarity). <br /> - We create a dictionary for User Info (we populate this in the actual code, but leaving it empty here). <br /> - <br />
  • - fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification. <br /> <br /> - 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. <br /> <br /> - repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year) <br /> <br /> - repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications. <br />
  • - fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification. <br /> <br /> - 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. <br /> <br /> - repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year) <br /> <br /> - repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications. <br />
  • - fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification. <br /> <br /> - 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. <br /> <br /> - repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year) <br /> <br /> - repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications. <br />
  • - fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification. <br /> <br /> - 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. <br /> <br /> - repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year) <br /> <br /> - repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications. <br />
  • - fireDate: NSDate defining the scheduled time. If you want a repeating notification, this is the time of the first scheduled notification. <br /> <br /> - 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. <br /> <br /> - repeatInterval: Defines the calendar period (NSCalendarUnit) to repeat the notification (ie. every day/week/month/year) <br /> <br /> - repeatCalendar: Defines the NSCalendar used to schedule the repeat notifications. <br />
  • - alertBody: Defines the message which will appear in the alert bubble. <br /> <br /> - hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to <br /> NO, requires alertBody to have a value! <br /> <br /> - alertAction: Title of the Slider/Action button on the pop-up <br /> <br /> - alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched. <br />
  • - alertBody: Defines the message which will appear in the alert bubble. <br /> <br /> - hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to <br /> NO, requires alertBody to have a value! <br /> <br /> - alertAction: Title of the Slider/Action button on the pop-up <br /> <br /> - alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched. <br />
  • - alertBody: Defines the message which will appear in the alert bubble. <br /> <br /> - hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to <br /> NO, requires alertBody to have a value! <br /> <br /> - alertAction: Title of the Slider/Action button on the pop-up <br /> <br /> - alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched. <br />
  • - alertBody: Defines the message which will appear in the alert bubble. <br /> <br /> - hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to <br /> NO, requires alertBody to have a value! <br /> <br /> - alertAction: Title of the Slider/Action button on the pop-up <br /> <br /> - alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched. <br />
  • - alertBody: Defines the message which will appear in the alert bubble. <br /> <br /> - hasAction: Controls whether the action buttons (or slider) are shown or hidden. If you set to <br /> NO, requires alertBody to have a value! <br /> <br /> - alertAction: Title of the Slider/Action button on the pop-up <br /> <br /> - alertLaunchImage: A filename in the app bundle to an image which is to be used instead of Default.png when the app is launched. <br />
  • applicationIconBadgeNumber: what count appears on the application&#x2019;s badge <br /> soundName: Filename to a sound file in the application bundle (needs to be &lt;30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info). <br /> userInfo: Dictionary containing application specific details. Must be valid property list types. <br />
  • applicationIconBadgeNumber: what count appears on the application&#x2019;s badge <br /> soundName: Filename to a sound file in the application bundle (needs to be &lt;30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info). <br /> userInfo: Dictionary containing application specific details. Must be valid property list types. <br />
  • applicationIconBadgeNumber: what count appears on the application&#x2019;s badge <br /> soundName: Filename to a sound file in the application bundle (needs to be &lt;30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info). <br /> userInfo: Dictionary containing application specific details. Must be valid property list types. <br />
  • applicationIconBadgeNumber: what count appears on the application&#x2019;s badge <br /> soundName: Filename to a sound file in the application bundle (needs to be &lt;30 seconds, using AIFF/WAV/CAF formats. See Apple&#x2019;s docs for more info). <br /> userInfo: Dictionary containing application specific details. Must be valid property list types. <br />
  • <br />
  • <br />
  • - Returns an Array of the pending notifications for your application (those which haven&#x2019;t yet fired). <br /> - Any notifications which you submitted & have been fired are lost - that may mean you need to cache notifications independently. <br /> - UILocalNotification objects are NSCoding compliant, so they can be serialised out. <br />
  • - Call cancelLocalNotification: with the UILocalNotification instance you wish to remove. <br /> <br />
  • - Call cancelLocalNotification: with the UILocalNotification instance you wish to remove. <br /> <br />
  • <br />
  • <br />
  • <br />
  • Not running? We then enter the application:didFinishLaunchingWithOptions: method in our app delegate. <br /> <br /> Check the launchOptions dictionary for the presence of UIApplicationLaunchOptionsLocalNotificationKey. <br /> <br /> If present, the associated value is a UILocalNotification object, which we can then process. <br />
  • Not running? We then enter the application:didFinishLaunchingWithOptions: method in our app delegate. <br /> <br /> Check the launchOptions dictionary for the presence of UIApplicationLaunchOptionsLocalNotificationKey. <br /> <br /> If present, the associated value is a UILocalNotification object, which we can then process. <br />
  • - is the replacement for applicationDidFinishLaunching: delegate method (added in iOS 3) <br /> <br />
  • - Delegate&#x2019;s application:didReceiveLocalNotification: method with the UILocalNotification instance <br />
  • - calling [application applicationState] lets us know if we&#x2019;re Active (meaning in foreground), Background (was running in background), or Inactive. <br /> <br /> - I used this check so I could emulate the notification alertview (as I didn&#x2019;t want my app to automatically respond). <br /> <br /> - Depending on your own app, you may want it to respond automatically. <br />
  • <br />

Local Notifications @ Melbourne Cocoaheads (Aug 10) Local Notifications @ Melbourne Cocoaheads (Aug 10) Presentation Transcript

  • Local Notifications Rob Caporetto @rob_caporetto www.rob-caporetto.com
  • What notifications?
  • What Notifications?
  • What Notifications? • Allows you to create 3 types
  • What Notifications? • Allows you to create 3 types • Badges
  • What Notifications? • Allows you to create 3 types • Badges • Sounds
  • What Notifications? • Allows you to create 3 types • Badges • Sounds • Alerts
  • Lifecycle
  • Creating a Notification
  • Creating a Notification • User performs an action.
  • Creating a Notification • User performs an action. • Create a UILocalNotification instance & configure it.
  • Creating a Notification • User performs an action. • Create a UILocalNotification instance & configure it. • Register the notification with the UIApplication instance.
  • Creating a Notification • User performs an action. • Create a UILocalNotification instance & configure it. • Register the notification with the UIApplication instance.
  • Creating a Notification • User performs an action. • Create a UILocalNotification instance & configure it. • Register the notification with the UIApplication instance.
  • Creating a Notification • User performs an action. • Create a UILocalNotification instance & configure it. • Register the notification with the UIApplication instance.
  • Receiving a Notification
  • Receiving a Notification • Some time passes…
  • Receiving a Notification • Some time passes… • If the device is locked, then we receive the notification bubble.
  • 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.
  • 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.
  • Receiving a Notification
  • Receiving a Notification • If the device is active and the application is not running, the notification bubble will appear.
  • 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
  • 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
  • Receiving a Notification
  • Receiving a Notification • If the application is in the foreground, then no notification is presented.
  • 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.
  • Adding Local Notifications
  • Creating a Notification
  • Creating a Notification • Alloc/init a UILocalNotification instance. • Configure its properties. • Register with the application’s UIApplication instance.
  • Creating a Notification NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60]; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.soundName = UILocalNotificationDefaultSoundName; notification.alertAction = @"View"; notification.alertBody = @"Here's our notification message!"; notification.userInfo = userInfo;
  • Creating a Notification
  • Creating a Notification • Scheduling Properties to set:
  • Creating a Notification • Scheduling Properties to set: • fireDate
  • Creating a Notification • Scheduling Properties to set: • fireDate • timeZone
  • Creating a Notification • Scheduling Properties to set: • fireDate • timeZone • repeatInterval
  • Creating a Notification • Scheduling Properties to set: • fireDate • timeZone • repeatInterval • repeatCalendar
  • Creating a Notification
  • Creating a Notification • Appearance Properties:
  • Creating a Notification • Appearance Properties: • alertBody
  • Creating a Notification • Appearance Properties: • alertBody • hasAction
  • Creating a Notification • Appearance Properties: • alertBody • hasAction • alertAction
  • Creating a Notification • Appearance Properties: • alertBody • hasAction • alertAction • alertLaunchImage
  • Creating a Notification
  • Creating a Notification • Other properties:
  • Creating a Notification • Other properties: • applicationIconBadgeNumber
  • Creating a Notification • Other properties: • applicationIconBadgeNumber • soundName
  • Creating a Notification • Other properties: • applicationIconBadgeNumber • soundName • userInfo
  • Scheduling
  • Scheduling • Get the UIApplication instance and call scheduleLocalNotification:
  • Scheduling • Get the UIApplication instance and call scheduleLocalNotification: [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  • Accessing Notifications • Call scheduledLocalNotifications
  • Cancelling Notifications
  • Cancelling Notifications • To cancel a single notification: • Call cancelLocalNotification:
  • Cancelling Notifications • To cancel a single notification: • Call cancelLocalNotification: • To cancel all notifications: • Call cancelAllLocalNotifications
  • Handling Notifications
  • Handling Notifications • Two entry points
  • Handling Notifications • Two entry points • Application is not running
  • Handling Notifications • Two entry points • Application is not running • Application is in foreground, or suspended
  • Handling Notifications
  • Handling Notifications • Not running?
  • Handling Notifications • Not running? • Check launchOptions dictionary?
  • Handling Notifications - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Perform normal delegate tasks... UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (notification != nil) { // Respond to notification } return YES; }
  • Handling Notifications • If we’re active, or have been backgrounded?
  • Handling Notifications - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { if ([application applicationState] == UIApplicationStateActive) { // Perform some custom notification logic } }
  • Other Resources • “Local and Push Notification Programming Guide” - developer.apple.com/iphone • “Session 129 - Implementing Local and Push Notifications” - WWDC 2010 videos