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.
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
maybeAction & declineAction are missing. I'm assuming it's similar to acceptAction? example:
PR is https://github.com/appcelerator/titanium_mobile/pull/5988
[~underlabs] Yes it is.
PR Merged
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
[~cng], thoughts?
All, please see TIMOB-17683 as well. Thoughts appreciated.
Closing ticket as fixed. Verified the fix in TIMOB-17640 and TIMOB-17707.