Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17238] iOS8: Add support for Interactive Notifications

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-08-28T22:52:31.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.4.0
ComponentsiOS
Labelsios8
ReporterIngo Muschenetz
AssigneeChee Kiat Ng
Created2014-06-29T07:57:47.000+0000
Updated2014-09-18T18:11:29.000+0000

Description

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*
var acceptAction = Ti.App.iOS.createUserNotificationAction({
    identifier: "ACCEPT_IDENTIFIER",
    title: "Accept",
    activationMode: Ti.App.iOS.NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
    destructive: false,
    authenticationRequired: false
}) ;
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*
var backgroundCategory = Ti.App.iOS.createUserNotificationCategory({
identifier: "BACKGROUND_CATEGORY",
actionsForDefaultContext: [acceptAction, maybeAction, declineAction],
actionsForMinimalContext: [acceptAction, declineAction]
});
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*
Ti.App.iOS.registerForLocalNotifications({
types: Ti.App.iOS.NOTIFICATION_TYPE_SOUND | Ti.App.iOS.NOTIFICATION_TYPE_ALERT,
categories: [backgroundCategory,backgroundLockCategory,foregroundCategory]
});
Note: categories: nil will allow local notifications to work without actions *4.Add event listeners*
// 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
});
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.

Attachments

FileDateSize
notificationSample.js2014-08-29T07:51:39.000+00005584

Comments

  1. James Sugrue 2014-07-01

    Details can be found on this feature in the WWDC talk "What's New in iOS Notifications" from 10:00 The class in question seems to be UIMutableUserNotificationAction
  2. Joseph Sachs 2014-08-26

    maybeAction & declineAction are missing. I'm assuming it's similar to acceptAction? example:
       var maybeAction = Ti.App.iOS.createUserNotificationAction({
           identifier: "MAYBE_IDENTIFIER", // is this right?
           title: "Maybe",
           activationMode: Ti.App.iOS.NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
           destructive: false,
           authenticationRequired: false
       }) ;
       
  3. Ingo Muschenetz 2014-08-26

    PR is https://github.com/appcelerator/titanium_mobile/pull/5988
  4. Chee Kiat Ng 2014-08-26

    [~underlabs] Yes it is.
  5. Pedro Enrique 2014-08-28

    PR Merged
  6. Timan Rebel 2014-09-11

    Wouldn't it have been better to give registerForLocalNotifications a more generic name, like registerForNotifications? Because to register for Push Notifications, you have to take the exact same native steps in iOS8, afaik. (Both are called UserNotifications). Now you first have to call registerForLocalNotifications and then Ti.Network.registerForPushNotifications. The latter no longer requesting permission (because the former already did). For me this was very confusing at first, until I took a look at the native iOS implementation. For more info see: https://developer.apple.com/videos/wwdc/2014/#713
  7. Ingo Muschenetz 2014-09-11

    [~cng], thoughts?
  8. Ingo Muschenetz 2014-09-11

    All, please see TIMOB-17683 as well. Thoughts appreciated.
  9. Wilson Luu 2014-09-18

    Closing ticket as fixed. Verified the fix in TIMOB-17640 and TIMOB-17707.

JSON Source