Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timob 17238 - iOS 8 Interactive Local Notifications #5988

Merged
merged 10 commits into from Aug 28, 2014
Merged

Conversation

cheekiatng
Copy link
Contributor

For iOS 8 or newer only.

Details: https://jira.appcelerator.org/browse/TIMOB-17238

New Feature:

Support for iOS 8 Interactive Local 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.

Chee Kiat Ng and others added 5 commits August 25, 2014 16:30
Added notificationAction and notificationCategory proxies
Working for local notifications
Only when we don’t register it under background service. Then both
delegates for foreground and background properly received and fired
push notifications support for interactive
Support for interactive notifications for local notifications. Also
included for remote notifications but require update to ACS backend
@@ -61,6 +61,9 @@ methods:
summary: The types of notifications required by the application separated by a bitwise-OR operator
constants: Titanium.App.iOS.NOTIFICATION_TYPE_*
type: Number
- name: categories
summary: The set of categories of user notification actions required by local and remote notifications
type: NSSet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NSSet is an Objective-C object. That should say "Array" instead

@pec1985
Copy link
Contributor

pec1985 commented Aug 26, 2014

Code reviewed, good job. Please address comments and I will test it after. Thanks.

Chee Kiat Ng and others added 3 commits August 27, 2014 14:41
Fixed coding style, documentation updated
updated copyright, and removed temporary test files

@interface TiAppiOSNotificationActionProxy : TiProxy {
@private
UIMutableUserNotificationAction *_notificationAction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to create a local variable if there's a retain property


if([TiUtils isIOS8OrGreater]) {
id category = [args objectForKey:@"category"];
if (category != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the category is a TiAppiOSNotificationCategoryProxy

@pec1985
Copy link
Contributor

pec1985 commented Aug 28, 2014

PR reviewed, and new changes submitted by myself. We need another reviewer before it can be merged.
@cheekiatng, If you have time, could create a simple test app that uses this api?

@pec1985
Copy link
Contributor

pec1985 commented Aug 28, 2014

Merging.

pec1985 added a commit that referenced this pull request Aug 28, 2014
Timob 17238 - iOS 8 Interactive Local Notifications
@pec1985 pec1985 merged commit 5c7ca2b into master Aug 28, 2014
@ingo ingo deleted the TIMOB-17238 branch November 19, 2014 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants