Push Notifications #iOS13 with Cordova PushPlugin
If you’re using phonegap-plugin-push 1.10.0 “PushPlugin” with Cordova and iOS13, then you will quickly notice, that in your callback, that the data.registrationId will be in the wrong format, something like:
{length=32,bytes=0x61a941c6799e63043d5366de0b865cbf...781fd5936a7efdc6}
as the device token, which will obviously not work.
So, there are solutions, like upgrading the push plugin, but for whatever reason, you can’t do that, here is the code change necessary to fix the plugin:
Open Plugins > PushPlugin.m
Scroll down to didRegisterForRemoteNotificationsWithDeviceToken
and remove this line of code:
NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@”<“withString:@””]
stringByReplacingOccurrencesOfString:@”>” withString:@””]
stringByReplacingOccurrencesOfString: @” ” withString: @””];
and replace this with:
NSUInteger length = deviceToken.length;
const unsigned char *buffer = deviceToken.bytes;
NSMutableString *hexString= [NSMutableString stringWithCapacity:(length * 2)];
for (int i = 0; i < length; ++i) {
[hexString appendFormat:@”%02x”, buffer[i]];
}
NSString *token = [hexString copy];
This is from https://onesignal.com/blog/ios-13-introduces-4-breaking-changes-to-notifications/ – So credit due, and respect to George Deglin for this fix.
With this fix, the registrationId goes back to normal, and push notifications work as before.