Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17707] iOS8: change Ti.App.iOS event name from 'backgroundNotification' to 'localnotificationaction'

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-09-26T20:15:37.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.4.0, Release 3.5.0
ComponentsiOS
Labelsn/a
ReporterJon Alter
AssigneeJon Alter
Created2014-09-16T21:12:37.000+0000
Updated2014-11-21T20:22:58.000+0000

Description

Change Ti.App.iOS event name from 'backgroundNotification' to 'localnotificationaction'. The current name of the event does not accurately reflect the purpose of the event. Because of this, it needs to be changed to something more meaningful.

Test Instructions

1. Run the code below 2. Click 'registerUserNotificationSettings' and then Allow 3. Click 'scheduleLocalNotification' 4. Background the app 5. Swipe down from the top of the device to see the notification center 6. Swipe the notification to the left and click one of the buttons 7. If 'localnotificationaction' is displayed in the device log, then the event was fired correctly
var rows = [
    {
        title: 'currentUserNotificationSettings',
        onClick: function(){
            // iOS 8 +
            var settings =  Ti.App.iOS.currentUserNotificationSettings;
            logUserNotificationSettings(settings);
        }
    },
    {
        title: 'registerUserNotificationSettings',
        onClick: function(){
            // iOS 8 +
            // The following action launches the application in the foreground and requires the device to be unlocked
            var acceptAction = Ti.App.iOS.createUserNotificationAction({
                identifier: "ACCEPT_IDENTIFIER",
                title: "Accept",
                activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_FOREGROUND,
                destructive: false,
                authenticationRequired: true
            });
 
            var foregroundCategory = Ti.App.iOS.createUserNotificationCategory({
                identifier: "FOREGROUND_CATEGORY",
                // The following actions will be displayed for an alert dialog
                actionsForDefaultContext: [acceptAction],
                // The following actions will be displayed for all other notifications
                actionsForMinimalContext: [acceptAction]
            });
 
            Ti.App.iOS.registerUserNotificationSettings({
                types: [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
                        // Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
                        Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE],
                categories: [foregroundCategory]
            });
        }
    },
    {
        title: 'scheduleLocalNotification',
        onClick: function(){
            Ti.App.iOS.scheduleLocalNotification({
                date: new Date(new Date().getTime() + 3000),
                alertBody: "New content available! Download now?",
                badge: 1,
                userInfo: {"url": "http://www.download.com/resource/asset.json"},
                category: "FOREGROUND_CATEGORY"
            });
        }
    }
];
 
function logInApp(text) {
    textLog.value = textLog.value + '\n' + text;
}
 
function logUserNotificationSettings(settings) {
    logInApp('UserNotificationSettings: ');
    logInApp('types: ' + JSON.stringify(settings.types));
    var categories = [];
    for (var i = 0, j = settings.categories.length; i < j; i++) {
        categories.push(settings.categories[i].identifier);
    }
    logInApp('categories: ' + JSON.stringify(categories));
}
 
Ti.App.iOS.addEventListener('usernotificationsettings', function(e) {
    logInApp('Event: usernotificationsettings');
    logUserNotificationSettings(e);
});

Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
    logInApp('localnotificationaction');
    logInApp('- category: ' + e.category + ' identifier: ' + e.identifier);
});
 
////////////////////////////////////////////////////////
// UI
////////////////////////////////////////////////////////
var win = Ti.UI.createWindow({
    backgroundColor: 'white'
});
win.open();
 
var textLog = Ti.UI.createTextArea({
    top: 0,
    height: '20%',
    width: '100%',
    borderWidth: '2',
    borderColor: '#000',
    value: 'AppLog: see device log for more info'
});
win.add(textLog);
 
var tableView = Ti.UI.createTableView({
    top: '20%',
    data: rows
});
tableView.addEventListener('click', function(e){
    e.source.onClick && e.source.onClick();
});
win.add(tableView);

Comments

  1. Jon Alter 2014-09-16

    master PR: https://github.com/appcelerator/titanium_mobile/pull/6101 3_4_X PR: https://github.com/appcelerator/titanium_mobile/pull/6102
  2. Wilson Luu 2014-09-17

    Closing ticket as fixed. Verified localnotification event gets fired instead of backgroundNotification. Tested on: Appcelerator Studio, build: 3.4.0.201409131030 SDK build: 3.4.0.v20140916151649 CLI: 3.4.0-rc4 Alloy: 1.5.0-rc2 Xcode: 6 GM Seed Device: iphone 5 (8.0 GM Seed)

JSON Source