appfeel / cordova-push-notifications

Phonegap, Cordova, Intel XDK push notifications support
MIT License
23 stars 25 forks source link

iOS 13 Device token key is broken #13

Open RamyaAshika opened 4 years ago

RamyaAshika commented 4 years ago

Hi,

As per the apple updates, iOS device token key is generating {length = 32, bytes = 789dc438 6d688f2c ... f6b37ddb 8a504523 }" instead of <789dc438 6d688f2c e2dd66d8 0d335454 5ce29f0f ed71234a f6b37ddb 8a504523>"

For reference, please go through this link. https://fluffy.es/4-ios13-breaking-changes/#push

So, what is the fix for this, I'm using cordova push notification plugin only and I'm facing this problem.Any updates?

codebycharles commented 4 years ago

Hi,

As per the apple updates, iOS device token key is generating {length = 32, bytes = 789dc438 6d688f2c ... f6b37ddb 8a504523 }" instead of <789dc438 6d688f2c e2dd66d8 0d335454 5ce29f0f ed71234a f6b37ddb 8a504523>"

For reference, please go through this link. https://fluffy.es/4-ios13-breaking-changes/#push

So, what is the fix for this, I'm using cordova push notification plugin only and I'm facing this problem.Any updates?

I've submitted a pull request to fix this issue, you can have a look.

DevelupDB commented 3 years ago

Hi, sorry for my English, I have the same problem and i could fix it.

The truth is, the easiest thing for some is to change the plugin since it is outdated and is not fully compatible with ios 13.

But if you want to continue using this plugin you must edit the PushPlugin.m file in the folder of plugin, more precisely the code of line 291, I leave the example in case someone needs it, I have already tried it and it has worked for me.

Code of Plugin:

  NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
                      stringByReplacingOccurrencesOfString:@">" withString:@""]
                     stringByReplacingOccurrencesOfString: @" " withString: @""];

Remplace with this code:

const unsigned *tokenBytes = [deviceToken bytes];

NSString *token = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                            ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                            ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                            ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

To update the plugin code on the platform, you need to remove the platform and re-add it

cordova platform rm ios
cordova platform add ios

Regards