Project: titanium
Issue TIMOB-17238: iOS8: Add support for Interactive Notifications
iOS 8 brings a new feature that allows users to perform actions against notifications. A short writeup is here: http://techcrunch.com/2014/06/02/actionable-push-notifications/ Apple has added notification action support so that user can immediately handle notifications in the home screen or lock screen, without the user having to enter the app. To enable this for both local and remote notifications, the following steps have to followed: 1. Create and Configure Notification Actions 2. Create and assign Notification Actions to Notification Categories 3. Register the Notification Categories and Notification Types 4. After which, add event listeners for notifications received while the app is active, or in background. *Detailed Steps:* *1. Create and Configure Notification Actions* {code:javascript} var acceptAction = Ti.App.iOS.createUserNotificationAction({ identifier: "ACCEPT_IDENTIFIER", title: "Accept", activationMode: Ti.App.iOS.NOTIFICATION_ACTIVATION_MODE_BACKGROUND, destructive: false, authenticationRequired: false }) ; {code} key parameters: activation Mode: NOTIFICATION_ACTIVATION_MODE_BACKGROUND, NOTIFICATION_ACTIVATION_MODE_FOREGROUND determines where app should be activated when user selects this action destructive: if this action does something permanent like delete authenticationRequired: if this action needs user to enter pin to continue *2.Create and assign Notification Actions to Notification Categories* {code:javascript} var backgroundCategory = Ti.App.iOS.createUserNotificationCategory({ identifier: "BACKGROUND_CATEGORY", actionsForDefaultContext: [acceptAction, maybeAction, declineAction], actionsForMinimalContext: [acceptAction, declineAction] }); {code} key parameters: actionsForDefaultContext: default actions to show. Will show all if user has set app to display notifications in alert style. actionsForMinimalContext(optional) : actions to show when user has set app to display notifications in banner style, and in lock screen. *3.Register the Notification Categories and Notification Types* {code:javascript} Ti.App.iOS.registerForLocalNotifications({ types: Ti.App.iOS.NOTIFICATION_TYPE_SOUND | Ti.App.iOS.NOTIFICATION_TYPE_ALERT, categories: [backgroundCategory,backgroundLockCategory,foregroundCategory] }); {code} Note: categories: nil will allow local notifications to work without actions *4.Add event listeners* {code:javascript} // for notifications received while app is in foreground Ti.App.iOS.addEventListener('notification',function(e) { var content = e.userInfo.content; //do stuff with notification received }); //for notifications received while app is in background Ti.App.iOS.addEventListener('backgroundNotification',function(e) { var content = e.userInfo.content; var identifier = e.identifier; //do stuff with notification received }); {code} Note: To enable interactive remote notifications, steps 1 to 3 should be done as well. Followed by Ti.Network.registerForPushNotifications. Require ACS to add additional field "category" to aps push packet, so that we can enable this for remote notifications.
Story points: 8