Cordova-plugin-firebase: unregister device

Created on 5 Sep 2017  路  9Comments  路  Source: arnesson/cordova-plugin-firebase

I have a settings menu where the user can set push notifications to on or off.

What I do now is window.FirebasePlugin.unregister();
If I do that, than I don't get any notifications anymore, which is great.
But if I want to register again with window.FirebasePlugin.getToken() , I do not get any notifications anymore. So I can't register again.

What am I doing wrong ?

All 9 comments

Hey, I have the same issue. I only use topics and I accidently unregistered(), now I don't know how to register back. Any idea ?

Is this the same issue I found at Stackoverflow, because I have an issue with Android (same as mentioned in the SO post). Unregistered device still gets notifications..

Yes it is the same issue, I asked that question on stackoverflow.

OK!

I just tried to fix it on Android by commenting out some code at platforms\androidsrc\org\apache\cordova\firebase\FirebasePlugin.java (ionic v1 project):

private void unregister(final CallbackContext callbackContext) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    FirebaseInstanceId.getInstance().deleteInstanceId();
                    /*
                    String currentToken = FirebaseInstanceId.getInstance().getToken();
                    if (currentToken != null) {
                        FirebasePlugin.sendToken(currentToken);
                    }
                    */
                    callbackContext.success();
                } catch (Exception e) {
                    callbackContext.error(e.getMessage());
                }
            }
        });
    }

It seems that the code was getting a new token right after unregistering the current one. Now it's working as expected on Android at least.

I've tried that with iOS by commenting out this code

- (void)unregister:(CDVInvokedUrlCommand *)command {
    [[FIRInstanceID instanceID] deleteIDWithHandler:^void(NSError *_Nullable error){
        if (error) {
            NSLog(@"Unable to delete instance");
        } else {
            /*NSString* currentToken = [[FIRInstanceID instanceID] token];
            if (currentToken != nil) {
                [self sendToken:currentToken];
            }*/
            CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
            [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
        }
    }];
}

But that didn't work. I still can't register again.

I have the same bug, someone has been able to solve it

I have this bug too. At least on Android, haven't tested iOS. I get a new token and continue to receive push notifications right after I've run the unregister() function.

@Regicollis I have solved it (#522)

closing as resolved, see comment

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JonSmart picture JonSmart  路  3Comments

chrissterling picture chrissterling  路  3Comments

dhavalsoni2001 picture dhavalsoni2001  路  5Comments

danielpalen picture danielpalen  路  5Comments

eilian92 picture eilian92  路  4Comments