Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19184] iOS9: Add behavior property to userNotificationAction

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2015-10-19T16:03:28.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.1.0
ComponentsiOS
Labelsnotification, pushnotification
ReporterChee Kiat Ng
AssigneeHans Knöchel
Created2015-07-07T08:11:02.000+0000
Updated2016-03-11T12:20:35.000+0000

Description

Via the userNotificationAction new property behavior, iOS9 now allows keyboard input as an action on the lock screen. Reference: https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS90APIDiffs/frameworks/UIKit.html Sample code:
var win = Ti.UI.createWindow({
    backgroundColor: "#fff"
});
var btn = Ti.UI.createButton({
    title: "Schedule local notification!"
});

btn.addEventListener("click", scheduleLocalNotification);

function scheduleLocalNotification() {

    var acceptAction = Ti.App.iOS.createUserNotificationAction({
        identifier: "ACCEPT_IDENTIFIER",
        title: "Reply",
        activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_FOREGROUND,
        destructive: false,
        behavior: Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_TEXTINPUT, // Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_DEFAULT,
        authenticationRequired: true
    });

    var invitationCategory = Ti.App.iOS.createUserNotificationCategory({
        identifier: "TEST_CATEGORY",
        actionsForDefaultContext: [acceptAction],
        actionsForMinimalContext: [acceptAction]
    });

    Ti.App.iOS.registerUserNotificationSettings({
        types: [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE],
        categories: [invitationCategory]
    });

    Ti.App.iOS.scheduleLocalNotification({
        date: new Date(new Date().getTime() + 3000),
        alertBody: "New message from Hans! Reply?",
        badge: 1,
        category: "TEST_CATEGORY"
    });
};

Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
    Ti.API.info(JSON.stringify(e));

    if (e.typedText && e.typedText.length > 0) {
        alert(e.typedText);
    }
});

win.add(btn);
win.open();

Attachments

FileDateSize
Screen Shot 2015-09-02 at 13.01.44.png2015-09-02T20:05:15.000+0000242127

Comments

  1. Hans Knöchel 2015-09-02

    [~cng] Implemented two new constants Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_DEFAULT and Ti.App.iOS.USER_NOTIFICATION_BEHAVIOR_TEXTINPUT, added the new property behavior to our proxy. Looks fine so far (see attached screen). Docs and sample are coming! Changed from 5.0.2 to 5.0.1, ok?
  2. Hans Knöchel 2015-09-02

    Sample code added. PR: https://github.com/appcelerator/titanium_mobile/pull/7120
  3. Chee Kiat Ng 2015-09-09

    PR Merged.
  4. Chee Kiat Ng 2015-09-11

    PR to fix backward compatibility with Xcode 6.4 here: https://github.com/appcelerator/titanium_mobile/pull/7165 PR merged
  5. Eric Wieber 2015-10-14

    Verified fixed, using: MacOS 10.11 (15A284) Studio 4.4.0.201510092420 Ti SDK 5.1.0.v20151013151603 Appc NPM 4.2.1-1 Appc CLI 5.1.0-38 Ti CLI 5.0.5 Alloy 1.7.16 Arrow 1.3.13 Xcode 7.0.1 (7A1001) Node v4.1.0 Java 1.7.0_80 production Able to successfully send, receive, and reply to user notifications in app, on the home screen, and on the lock screen. Used the provided sample code and made modifications to test the different scenarios.
  6. Eric Wieber 2015-10-16

    Reopening to address push notifications
  7. Hans Knöchel 2015-10-18

    Spent my day to reproduce the outstanding issue with remote notifications. They work. We need to supply a category in the aps like done natively and proposed by Apple:
       {
         "alert": "Test"
         "category": "INVITE_CATEGORY"
       }
       
    The text fields appears and the callback works. [~ewieber] please confirm and close the issue.
  8. Eric Wieber 2015-10-19

    Verified fixed using: MacOS 10.11 (15A284) Studio 4.4.0.201510161811 Ti SDK 5.1.0.v20151016172827 Appc NPM 4.2.1-5 Appc CLI 5.1.0-38 Ti CLI 5.0.5 Alloy 1.7.16 Arrow 1.3.13 Xcode 7.0.1 (7A1001) Node v0.12.7 Java 1.7.0_80 production Remote notifications work as well. Push notifications sent can be interacted with via buttons and text input on the home and lock screens.

JSON Source