Skip to content

Commit

Permalink
Merge pull request #100 from vzivanovvegait/master
Browse files Browse the repository at this point in the history
Added method to retrieve APNSToken
  • Loading branch information
dpa99c authored Aug 30, 2019
2 parents fda2d51 + 73aced2 commit 469165e
Show file tree
Hide file tree
Showing 3 changed files with 18 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 @@ -8,6 +8,7 @@
- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command;
- (void)getId:(CDVInvokedUrlCommand*)command;
- (void)getToken:(CDVInvokedUrlCommand*)command;
- (void)getDeviceToken:(CDVInvokedUrlCommand*)command;
- (void)grantPermission:(CDVInvokedUrlCommand*)command;
- (void)hasPermission:(CDVInvokedUrlCommand*)command;
- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command;
Expand Down
13 changes: 13 additions & 0 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ - (void)getToken:(CDVInvokedUrlCommand *)command {
}
}

- (void)getDeviceToken:(CDVInvokedUrlCommand *)command {
NSData* apnsToken = [FIRMessaging messaging].APNSToken;
CDVPluginResult *pluginResult;
if (apnsToken) {
NSString* hexToken = [[apnsToken.description componentsSeparatedByCharactersInSet:[[NSCharacterSet alphanumericCharacterSet]invertedSet]]componentsJoinedByString:@""];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:hexToken];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)hasPermission:(CDVInvokedUrlCommand *)command {
@try {
[self _hasPermission:^(BOOL enabled) {
Expand Down
4 changes: 4 additions & 0 deletions www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ exports.getToken = function (success, error) {
exec(success, error, "FirebasePlugin", "getToken", []);
};

exports.getDeviceToken = function (success, error) {
exec(success, error, "FirebasePlugin", "getDeviceToken", []);
};

exports.onMessageReceived = function (success, error) {
exec(success, error, "FirebasePlugin", "onMessageReceived", []);
};
Expand Down

0 comments on commit 469165e

Please sign in to comment.