Skip to content

Commit

Permalink
(iOS) Fix onTokenRefresh to return FCM token (not installation auth…
Browse files Browse the repository at this point in the history
… token). Resolves #637.
  • Loading branch information
Dave Alden committed Jul 23, 2021
1 parent 209b2f7 commit 5a3f907
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
43 changes: 21 additions & 22 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,25 @@ - (void)getId:(CDVInvokedUrlCommand *)command {
}

- (void)getToken:(CDVInvokedUrlCommand *)command {
[[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) {
@try {
[self handleStringResultWithPotentialError:error command:command result:token];
}@catch (NSException *exception) {
[self handlePluginExceptionWithContext:exception :command];
}
[self _getToken:^(NSString *token, NSError *error) {
[self handleStringResultWithPotentialError:error command:command result:token];
}];
}

-(void)_getToken:(void (^)(NSString *token, NSError *error))completeBlock {
@try {
[[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) {
@try {
completeBlock(token, error);
}@catch (NSException *exception) {
[self handlePluginExceptionWithoutContext:exception];
}
}];
}@catch (NSException *exception) {
[self handlePluginExceptionWithoutContext:exception];
}
}

- (void)getAPNSToken:(CDVInvokedUrlCommand *)command {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[self getAPNSToken]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
Expand Down Expand Up @@ -430,22 +440,11 @@ - (void)onMessageReceived:(CDVInvokedUrlCommand *)command {

- (void)onTokenRefresh:(CDVInvokedUrlCommand *)command {
self.tokenRefreshCallbackId = command.callbackId;
@try {
[[FIRInstallations installations] authTokenForcingRefresh:true
completion:^(FIRInstallationsAuthTokenResult *result, NSError *error) {
@try {
if (error != nil) {
[self sendPluginErrorWithError:error command:command];
}else{
[self sendPluginStringResult:[result authToken] command:command callbackId:command.callbackId];
}
}@catch (NSException *exception) {
[self handlePluginExceptionWithContext:exception :command];
}
}];
}@catch (NSException *exception) {
[self handlePluginExceptionWithContext:exception :command];
}
[self _getToken:^(NSString *token, NSError *error) {
if(error == nil && token != nil){
[self sendToken:token];
}
}];
}

- (void)onApnsTokenReceived:(CDVInvokedUrlCommand *)command {
Expand Down
9 changes: 5 additions & 4 deletions www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ exports._onInstallationIdChangeCallback = function(installationId){
**************/

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

exports.getToken = function (success, error) {
exec(success, error, "FirebasePlugin", "getToken", []);
};
Expand Down Expand Up @@ -443,6 +439,11 @@ exports.functionsHttpsCallable = function (name, args, success, error) {
exec(success, error, "FirebasePlugin", "functionsHttpsCallable", [name, args]);
};

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

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

0 comments on commit 5a3f907

Please sign in to comment.