From ef80e68d4144dd2b260ef88c31a85b1cc50b3f9b Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 14 Nov 2019 12:04:58 +0100 Subject: [PATCH] And anotehr try... narf --- packaging/ios/pushnotifications.mm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packaging/ios/pushnotifications.mm b/packaging/ios/pushnotifications.mm index fb7067a2..58845af2 100644 --- a/packaging/ios/pushnotifications.mm +++ b/packaging/ios/pushnotifications.mm @@ -26,10 +26,22 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"Did Register for Remote Notifications with Device Token (%@)", deviceToken); - NSString *token = [self hexadecimalStringFromData:deviceToken]; + NSString *token = [self stringFromDeviceToken:deviceToken]; PushNotifications::instance()->setAPNSRegistrationToken(QString::fromNSString(token)); } ++ (NSString *)stringFromDeviceToken:(NSData *)deviceToken { + NSUInteger length = deviceToken.length; + if (length == 0) { + return nil; + } + const unsigned char *buffer = (const unsigned char*)deviceToken.bytes; + NSMutableString *hexString = [NSMutableString stringWithCapacity:(length * 2)]; + for (int i = 0; i < length; ++i) { + [hexString appendFormat:@"%02x", buffer[i]]; + } + return [hexString copy]; +} - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Did Fail to Register for Remote Notifications"); NSLog(@"%@, %@", error, error.localizedDescription);