Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-17707

iOS8: change Ti.App.iOS event name from 'backgroundNotification' to 'localnotificationaction'

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Release 3.4.0, Release 3.5.0
    • Component/s: iOS
    • Labels:
      None
    • Story Points:
      3
    • Sprint:
      2014 Sprint 19 SDK

      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);
      

        Attachments

          Activity

            People

            • Assignee:
              jalter Jon Alter
              Reporter:
              jalter Jon Alter
              Tester:
              Dustin Hyde
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Source Code