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 ?
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