Skip to content

Commit

Permalink
Process token on iOS 13+
Browse files Browse the repository at this point in the history
closes #27
  • Loading branch information
José Pereda authored Jan 6, 2020
2 parents 2e633a1 + 6818efb commit 4b12544
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions modules/push-notifications/src/main/native/ios/PushNotifications.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificatio
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
{

NSString * deviceTokenString = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
NSString *deviceTokenString = [self stringFromDeviceToken:deviceToken];
#else
NSString *deviceTokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
#endif

const char *deviceTokenChars = [deviceTokenString UTF8String];
jstring argToken = (*env)->NewStringUTF(env, deviceTokenChars);
Expand All @@ -146,6 +149,19 @@ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotif
[pool drain];
}

- (NSString *)stringFromDeviceToken:(NSData *)deviceToken {
NSUInteger length = deviceToken.length;
if (length == 0) {
return nil;
}
const unsigned char *buffer = deviceToken.bytes;
NSMutableString *hexString = [NSMutableString stringWithCapacity:(length * 2)];
for (int i = 0; i < length; ++i) {
[hexString appendFormat:@"%02x", buffer[i]];
}
return [hexString copy];
}

- (void) logMessage:(NSString *)format, ...;
{
if (debugPushNotifications)
Expand Down

0 comments on commit 4b12544

Please sign in to comment.