Skip to content

Commit

Permalink
Merge pull request #177 from russmedia-digital/bugfix/ios-13-apns-tok…
Browse files Browse the repository at this point in the history
…en-format-change

iOS 13 APNS format token change
  • Loading branch information
dpa99c authored Oct 21, 2019
2 parents b95ff1b + e19610e commit 132f24c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- (void)getId:(CDVInvokedUrlCommand*)command;
- (void)getToken:(CDVInvokedUrlCommand*)command;
- (void)getAPNSToken:(CDVInvokedUrlCommand*)command;
- (NSString *)hexadecimalStringFromData:(NSData *)data;
- (void)grantPermission:(CDVInvokedUrlCommand*)command;
- (void)hasPermission:(CDVInvokedUrlCommand*)command;
- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command;
Expand Down
20 changes: 20 additions & 0 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ - (void)getAPNSToken:(CDVInvokedUrlCommand *)command {
NSData* apnsToken = [FIRMessaging messaging].APNSToken;
CDVPluginResult *pluginResult;
if (apnsToken) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
// [deviceToken description] Starting with iOS 13 device token is like "{length = 32, bytes = 0xd3d997af 967d1f43 b405374a 13394d2f ... 28f10282 14af515f }"
NSString* hexToken = [self hexadecimalStringFromData:apnsToken];
#else
NSString* hexToken = [[apnsToken.description componentsSeparatedByCharactersInSet:[[NSCharacterSet alphanumericCharacterSet]invertedSet]]componentsJoinedByString:@""];
#endif
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:hexToken];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
Expand All @@ -90,6 +95,21 @@ - (void)getAPNSToken:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (NSString *)hexadecimalStringFromData:(NSData *)data
{
NSUInteger dataLength = data.length;
if (dataLength == 0) {
return nil;
}

const unsigned char *dataBuffer = data.bytes;
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
for (int i = 0; i < dataLength; ++i) {
[hexString appendFormat:@"%02x", dataBuffer[i]];
}
return [hexString copy];
}

- (void)hasPermission:(CDVInvokedUrlCommand *)command {
@try {
[self _hasPermission:^(BOOL enabled) {
Expand Down

0 comments on commit 132f24c

Please sign in to comment.