Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26319] iOS: "usernotificationsettings" does not include "types" array on iOS 10 and SDK 7.3.0

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-08-21T07:11:14.000+0000
Affected Version/sRelease 7.3.0
Fix Version/sRelease 7.3.1
ComponentsiOS
Labelsn/a
ReporterHans Knöchel
AssigneeHans Knöchel
Created2018-08-20T06:25:43.000+0000
Updated2018-08-21T10:54:20.000+0000

Description

When using iOS 10+ on SDK 7.3.0, the "usernotificationsettings" event does not include the "types" array of granted types anymore. An easy workaround is to use the following code, but ideally it should be 100 % backwards compatible. Workaround:
Ti.App.iOS.NotificationCenter.requestUserNotificationSettings(event => {
    const alertSetting = event.alertSetting;
    const badgeSetting = event.badgeSetting;
    const soundSetting = event.soundSetting;
    
    if (alertSetting === Ti.App.iOS.USER_NOTIFICATION_SETTING_ENABLED) {
        // Alert allowed
    }
});

Comments

  1. Hans Knöchel 2018-08-20

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10267 PR (7_3_X): https://github.com/appcelerator/titanium_mobile/pull/10268 Test-Case:
       var win = Ti.UI.createWindow({
           backgroundColor: '#fff'
       });
       
       var btn = Ti.UI.createButton({
           title: 'Trigger'
       });
       
       btn.addEventListener('click', function() {
         // An action that opens the app (foreground action)
         var acceptAction = Ti.App.iOS.createUserNotificationAction({
           identifier: 'ACCEPT_IDENTIFIER',
           title: 'Accept',
           activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_FOREGROUND,
           destructive: false,
           authenticationRequired: true
         });
         
         // An action that does not open the app (background action)
         var rejectAction = Ti.App.iOS.createUserNotificationAction({
           identifier: 'REJECT_IDENTIFIER',
           title: 'Reject',
           activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
           destructive: true,
           authenticationRequired: false
         });
         
         // Create a notification category
         var downloadContent = Ti.App.iOS.createUserNotificationCategory({
           identifier: 'DOWNLOAD_CONTENT',
           actionsForDefaultContext: [ acceptAction, rejectAction ]
         });
       
           Ti.App.iOS.registerUserNotificationSettings({
               types: [
                   Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
                   Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE,
                   Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND
               ],
               categories: [downloadContent]
           });
       });
       
       Ti.App.iOS.addEventListener('usernotificationsettings', function (e) {
           // Verify that the "types" and "categories" are included
           Ti.API.warn(e);
       });
       
       win.add(btn);
       win.open();
       
  2. Samir Mohammed 2018-08-21

    *Closing ticket*. Verified fix with SDK version: 7.3.1.v20180821020403 and 7.4.0.v20180820235132. "usernotificationsettings" now includes "types" array on iOS 10+ and SDK 7.3.0.

    Created a titanium application with the test case above

    Ran the program

    Pressed the Trigger button on the application

    Able to see the console log show more information (iOS 10+) ("usernotificationsettings" including "types" array)

       [WARN] :   {
       [WARN] :       bubbles = 1;
       [WARN] :       cancelBubble = 0;
       [WARN] :       categories =     (
       [WARN] :           "[object TiAppiOSUserNotificationCategory]"
       [WARN] :       );
       [WARN] :       source = "[object TiAppiOS]";
       [WARN] :       type = usernotificationsettings;
       [WARN] :       types =     (
       [WARN] :           4,
       [WARN] :           1,
       [WARN] :           2
       [WARN] :       );
       [WARN] :   }
       

    Previously only the following information would be seen on iOS 10+ (7.3.0.GA)

       [WARN] :   {
       [WARN] :       bubbles = 1;
       [WARN] :       cancelBubble = 0;
       [WARN] :       source = "[object TiAppiOS]";
       [WARN] :       success = 1;
       [WARN] :       type = usernotificationsettings;
       [WARN] :   }
       
    *Test Environment*
       APPC Studio:  5.1.0.201808080937
       APPC CLI: 7.0.5
       iphone 6 simulator (11.2)
       iphone 6 simulator (10.3)
       iphone 6 simulator (9.3)
       Operating System Name: Mac OS High Sierra
       Operating System Version: 10.13
       Node.js Version: 8.9.1
       Xcode 9.2
       

JSON Source