diff --git a/modules/push-notifications/src/main/native/ios/PushNotifications.m b/modules/push-notifications/src/main/native/ios/PushNotifications.m index 24e60a99..16322d0f 100644 --- a/modules/push-notifications/src/main/native/ios/PushNotifications.m +++ b/modules/push-notifications/src/main/native/ios/PushNotifications.m @@ -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); @@ -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)