[TIMOB-26319] iOS: "usernotificationsettings" does not include "types" array on iOS 10 and SDK 7.3.0
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | High |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2018-08-21T07:11:14.000+0000 |
| Affected Version/s | Release 7.3.0 |
| Fix Version/s | Release 7.3.1 |
| Components | iOS |
| Labels | n/a |
| Reporter | Hans Knöchel |
| Assignee | Hans Knöchel |
| Created | 2018-08-20T06:25:43.000+0000 |
| Updated | 2018-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
}
});
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();*Closing ticket*. Verified fix with SDK version:
7.3.1.v20180821020403and7.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
Triggerbutton on the applicationAble 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)
*Test Environment*[WARN] : { [WARN] : bubbles = 1; [WARN] : cancelBubble = 0; [WARN] : source = "[object TiAppiOS]"; [WARN] : success = 1; [WARN] : type = usernotificationsettings; [WARN] : }