From 69312b2402e8de7d002aecfb0d1cf4a8bf20c09f Mon Sep 17 00:00:00 2001 From: ChrisTomAlx Date: Thu, 26 Sep 2019 15:59:36 +0530 Subject: [PATCH] ios 13 support --- package.json | 2 +- plugin.xml | 2 +- src/ios/APNSPushPlugin.m | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bce373a..4d79ce4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cordova-plugin-apns-push", "description": "Register and receive APNS push notifications.", - "version": "1.0.0", + "version": "1.0.1", "repository": { "type": "git", "url": "https://github.com/NeutrinosPlatform/cordova-plugin-apns-push" diff --git a/plugin.xml b/plugin.xml index bb2a5ca..f4c2863 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="1.0.1"> APNSPushPlugin This plugin allows your application to receive apple push notifications (APNS) on iOS devices. diff --git a/src/ios/APNSPushPlugin.m b/src/ios/APNSPushPlugin.m index 77c7d11..90cb321 100644 --- a/src/ios/APNSPushPlugin.m +++ b/src/ios/APNSPushPlugin.m @@ -340,9 +340,16 @@ } NSLog(@"Push Plugin register success: %@", deviceToken); +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 + // [deviceToken description] is like "{length = 32, bytes = 0xd3d997af 967d1f43 b405374a 13394d2f ... 28f10282 14af515f }" + NSString *token = [self hexadecimalStringFromData:deviceToken]; +#else + // [deviceToken description] is like "<124686a5 556a72ca d808f572 00c323b9 3eff9285 92445590 3225757d b83967be>" NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString: @" " withString: @""]; +#endif + #if !TARGET_IPHONE_SIMULATOR // Check what Notifications the user has turned on. We registered for all three, but they may have manually disabled some or all of them. @@ -360,6 +367,21 @@ #endif } +- (NSString *)hexadecimalStringFromData:(NSData *)data +{ + NSUInteger dataLength = data.length; + if (dataLength == 0) { + return nil; + } + + const unsigned char *dataBuffer = data.bytes; + NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)]; + for (int i = 0; i < dataLength; ++i) { + [hexString appendFormat:@"%02x", dataBuffer[i]]; + } + return [hexString copy]; +} + - (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { if (self.callbackId == nil) {