Skip to content

Commit 71b14d6

Browse files
authored
E2-2047: update method to get push token for iOS 13 (#316)
1 parent 74c044c commit 71b14d6

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Example/Tests/Classes/LPActionManagerTest.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo
4343
withAction:(NSString *)action
4444
fetchCompletionHandler:(LeanplumFetchCompletionBlock)completionHandler;
4545
- (void)leanplum_application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
46+
- (NSString *)hexadecimalStringFromData:(NSData *)data;
4647
@end
4748

4849
@interface LPActionManagerTest : XCTestCase
@@ -309,6 +310,14 @@ - (void)test_active_period_true
309310

310311
}
311312

313+
-(void)testHexadecimalStringFromData {
314+
LPActionManager *manager = [[LPActionManager alloc] init];
315+
NSString *testString = @"74657374537472696e67";
316+
NSData *data = [self hexDataFromString:testString];
317+
NSString *parsedString = [manager hexadecimalStringFromData:data];
318+
XCTAssertEqualObjects(testString, parsedString);
319+
}
320+
312321
#pragma mark Helpers
313322

314323
-(NSDictionary *)messageConfigInActivePeriod:(BOOL)inActivePeriod
@@ -324,4 +333,22 @@ -(NSDictionary *)messageConfigInActivePeriod:(BOOL)inActivePeriod
324333
};
325334
return config;
326335
}
336+
337+
-(NSMutableData*)hexDataFromString:(NSString*)string {
338+
339+
NSMutableData *hexData= [[NSMutableData alloc] init];
340+
unsigned char whole_byte;
341+
char byte_chars[3] = {'\0','\0','\0'};
342+
int i;
343+
for (i=0; i < [string length]/2; i++) {
344+
byte_chars[0] = [string characterAtIndex:i*2];
345+
byte_chars[1] = [string characterAtIndex:i*2+1];
346+
whole_byte = strtol(byte_chars, NULL, 16);
347+
[hexData appendBytes:&whole_byte length:1];
348+
}
349+
return hexData;
350+
}
351+
352+
353+
327354
@end

Leanplum-SDK/Classes/Features/Actions/LPActionManager.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
752752
}
753753

754754
// Format push token.
755-
NSString *formattedToken = [token description];
755+
NSString *formattedToken = [self hexadecimalStringFromData:token];
756756
formattedToken = [[[formattedToken stringByReplacingOccurrencesOfString:@"<" withString:@""]
757757
stringByReplacingOccurrencesOfString:@">" withString:@""]
758758
stringByReplacingOccurrencesOfString:@" " withString:@""];
@@ -1320,4 +1320,20 @@ - (void)muteFutureMessagesOfKind:(NSString *)messageId
13201320
}
13211321
}
13221322

1323+
#pragma mark - Helper methods
1324+
- (NSString *)hexadecimalStringFromData:(NSData *)data
1325+
{
1326+
NSUInteger dataLength = data.length;
1327+
if (dataLength == 0) {
1328+
return nil;
1329+
}
1330+
1331+
const unsigned char *dataBuffer = data.bytes;
1332+
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
1333+
for (int i = 0; i < dataLength; ++i) {
1334+
[hexString appendFormat:@"%02x", dataBuffer[i]];
1335+
}
1336+
return [hexString copy];
1337+
}
1338+
13231339
@end

0 commit comments

Comments
 (0)