I'm using phonegap-plugin-push in an ionic 3 app.
However lately as more phones get updated to iOS 13 and above the registration of devices wont work anymore.
Device makes a call to an api on our side that in turn registeres phone with azure push hub.
This is how i have set up the registration process ionic.
const options: PushOptions = {
android: {
senderID: "58846546653626",
icon: 'pushicon',
iconColor: '#7BC3AD' //light blue green thingy
},
ios: {
alert: "true",
badge: "true",
sound: "true"
}
};
this.pushObject = this.push.init(options);
this.pushObject.on('registration').subscribe(data => {
this.pushRegister(data);
});
pushRegister(data: any) {
// Get the native platform of the device.
let platform: any = device.platform;
// Get the handle returned during registration.
let handle: any = data.registrationId;
// Set the device-specific message template.
let infoToRegister: any = {
"Platform": (platform == 'android' || platform == 'Android') ? 'gcm' : 'apns',
"DeviceToken": handle,
"Tags": [] //set serverside based on authorization
}
let url = (globalVars.serverurl+ 'api/Register');
let options = this.dataService.getRequestOptions();
let body: string = JSON.stringify(infoToRegister);
this.httpClient.post(url, body, options).subscribe(successResponse => {
console.log(successResponse);
}, errorResponse => {
console.log(errorResponse);
});
}
This all works well with phones running iOS below 13.
However with iOS 13 registrationId looks totally different and the api method that registered to azure push hub throws an error: One or more characters in device token is not a hexadecimal digit.
Example of posted data from iOS 13 that fails:
{"Platform":"apns","DeviceToken":"{length=32,bytes=0xc0d97379b07611f8e4e7529e3ee02e1d...d0a4e98468524d88}","Tags":[]}
Is there any way to get the correct token ? as seen above the bytes is also truncated so i guess i cant register with that either.
If anyone comes across this question and is not using Ionic, but it using plain Cordova, the solution is to update your phonegap-plugin-push
plugin to version 2.3.0 or higher (the pull request containing the fix is here: https://github.com/phonegap/phonegap-plugin-push/pull/2808 ).
You can verify that you have the correct version of the plugin installed by running the command: cordova plugins
For good measure, make sure that you run cordova platform remove ios
and cordova platform add ios
after updating the push notification plugin to ensure that the updated plugin is properly built into the compiled app. There are a number of ways that an old version of the plugin can persist in the compiled app.