diff --git a/packaging/ios/pushnotifications.mm b/packaging/ios/pushnotifications.mm index b4688bf9..8f8277c0 100644 --- a/packaging/ios/pushnotifications.mm +++ b/packaging/ios/pushnotifications.mm @@ -26,13 +26,17 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"Did Register for Remote Notifications with Device Token (%@)", deviceToken); - const unsigned *tokenBytes = (const unsigned*)[deviceToken bytes]; - NSString *tokenStr = [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])]; - PushNotifications::instance()->setAPNSRegistrationToken(QString::fromNSString(tokenStr)); +#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 + PushNotifications::instance()->setAPNSRegistrationToken(QString::fromNSString(token)); } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {