Skip to content

Commit

Permalink
fix(ios): correctly decode device token for ios 13 compatability (#11202
Browse files Browse the repository at this point in the history
)

* fix(ios): correctly decode device token for ios 13 compatability

Fixes TIMOB-27386

* fix(ios): correct call for converting nsdata to hex

Now we use something that actually exists\!
  • Loading branch information
ewanharris authored and lokeshchdhry committed Sep 10, 2019
1 parent 11aef9c commit 715ef61
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
7 changes: 2 additions & 5 deletions iphone/Classes/NetworkModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,8 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificatio
{
// called by TiApp
if (pushNotificationSuccess != nil) {
NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">"
withString:@""]
stringByReplacingOccurrencesOfString:@" "
withString:@""];
NSString *token = [TiUtils convertToHexFromData:deviceToken];

NSMutableDictionary *event = [TiUtils dictionaryWithCode:0 message:nil];
[event setObject:token forKey:@"deviceToken"];
[self _fireEventToListener:@"remote" withObject:event listener:pushNotificationSuccess thisObject:nil];
Expand Down
7 changes: 2 additions & 5 deletions iphone/Classes/TiApp+Addons.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,8 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">"
withString:@""]
stringByReplacingOccurrencesOfString:@" "
withString:@""];

NSString *token = [TiUtils convertToHexFromData:deviceToken];

RELEASE_TO_NIL(remoteDeviceUUID);
remoteDeviceUUID = [token copy];
Expand Down
2 changes: 2 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ typedef enum {
*/
+ (NSString *)convertToHex:(unsigned char *)input length:(size_t)length;

+ (NSString *)convertToHexFromData:(NSData *)data;

+ (NSString *)getResponseHeader:(NSString *)header fromHeaders:(NSDictionary *)responseHeaders;

+ (UIImage *)loadBackgroundImage:(id)image forProxy:(TiProxy *)proxy;
Expand Down
13 changes: 13 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,19 @@ + (NSString *)convertToHex:(unsigned char *)result length:(size_t)length
return value;
}

+ (NSString *)convertToHexFromData:(NSData *)data
{
NSUInteger dataLength = data.length;
unsigned char *dataBytes = (unsigned char *)data.bytes;
NSMutableString *encoded = [[NSMutableString alloc] initWithCapacity:dataLength * 2];
for (int i = 0; i < dataLength; i++) {
[encoded appendFormat:@"%02x", dataBytes[i]];
}
NSString *value = [encoded lowercaseString];
[encoded release];
return value;
}

+ (NSString *)md5:(NSData *)data
{
unsigned char result[CC_MD5_DIGEST_LENGTH];
Expand Down

0 comments on commit 715ef61

Please sign in to comment.