Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27386] iOS: Correctly decode push notification token

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2019-09-16T09:28:53.000+0000
Affected Version/sRelease 8.2.0, Release 8.1.1
Fix Version/sRelease 8.2.0
ComponentsiOS
LabelsengSchedule
ReporterEwan Harris
AssigneeEwan Harris
Created2019-09-09T13:12:07.000+0000
Updated2021-01-06T08:42:46.000+0000

Description

Description

On iOS 13 registering for push notifications returns an invalid device token, this is because the way we decode the device token has been broken by apple (although it seems it wasnt a recommended way anyways) See https://github.com/OneSignal/OneSignal-iOS-SDK/pull/509
Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
 
    // Remove event listener once registered for push notifications
    Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush); 
 
    Ti.Network.registerForPushNotifications({
        success: deviceTokenSuccess,
        error: deviceTokenError,
        callback: receivePush
    });
});
 
// Register notification types to use
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
    ]
});
 
// Process incoming push notifications
function receivePush(e) {
    alert('Received push: ' + JSON.stringify(e));
}
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
	console.log('Yay it worked!');
	console.log(e);
}
 
function deviceTokenError(e) {
	console.log('Failed to register for push notifications! ' + e.error);
	console.log(e);
}

Steps to reproduce

1. Add the below code to an app.js or alloy.js

Actual

The device token printed looks like
{length=32,bytes=0x17b4427542a3d1e6a4d69d976b4539bc...7edb18a21200a8d2}

Expected

The device token should look like
17b4427542a3d1e6a4d69d976b4539bcf227f216b02b5fd97edb18a21200a8d2

Comments

  1. Ewan Harris 2019-09-09

    master: https://github.com/appcelerator/titanium_mobile/pull/11202 8_2_X: https://github.com/appcelerator/titanium_mobile/pull/11203
  2. Ewan Harris 2019-09-10

    fixed 8_2_X PR: https://github.com/appcelerator/titanium_mobile/pull/11207
  3. Samir Mohammed 2019-09-10

    FR Passed. Waiting on Jenkins builds for Master and 8_2_X.
  4. Christopher Williams 2019-09-12

    master PR was already merged. Merged 8_2_X PR.
  5. Samir Mohammed 2019-09-16

    Closing ticket. Fix verified in SDK version 8.2.0.v20190912104344 and SDK version 8.3.0.v20190913104800. Test and other information can be found at: master: https://github.com/appcelerator/titanium_mobile/pull/11202 8_2_X: https://github.com/appcelerator/titanium_mobile/pull/11203

JSON Source