This repository was archived by the owner on Sep 4, 2020. It is now read-only.
Delete FCM instanceID when unregistering - iOS#2509
Open
malwatte wants to merge 7 commits intophonegap:masterfrom
Open
Delete FCM instanceID when unregistering - iOS#2509malwatte wants to merge 7 commits intophonegap:masterfrom
malwatte wants to merge 7 commits intophonegap:masterfrom
Conversation
Added code to delete Firebase token when unregistering in iOS
6 tasks
macdonst
suggested changes
Aug 2, 2018
| NSLog(@"unsubscribe from topic: %@", topic); | ||
| [pubSub unsubscribeFromTopic:topic]; | ||
| } | ||
| } else { |
Member
There was a problem hiding this comment.
Instead of adding an else if what about putting that code inside the else statement? So…
else {
if ([self usesFCM]) {
[[FIRInstanceID instanceID] deleteIDWithHandler:^void(NSError *_Nullable error){
if (error) {
[self failWithMessage:command.callbackId withMsg:@"" withError:error];
} else {
[self successWithMessage:command.callbackId withMsg:@"unregistered"];
}
}];
}
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
[self successWithMessage:command.callbackId withMsg:@"unregistered"];
}
This way the APNS token will get released as well.
Contributor
Author
There was a problem hiding this comment.
Yeah. Let me do that.
I do not know how APNS token works. Thats why I put inside an else. hehe.
Contributor
Author
There was a problem hiding this comment.
I tested it and there is a small problem. Success callback gets called even when FCM token delete failed. So I did something like this,
} else if ([self usesFCM]){
[[FIRInstanceID instanceID] deleteIDWithHandler:^void(NSError *_Nullable error){
if (error) {
[self failWithMessage:command.callbackId withMsg:@"" withError:error];
} else {
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
[self successWithMessage:command.callbackId withMsg:@"unregistered"];
}
}];
} else {
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
[self successWithMessage:command.callbackId withMsg:@"unregistered"];
}
Should be fine. Right?
PushInstanceIDListenerService doesn't have to be exported. So explicitly set the exported value to false
Update plugin.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
FCM Instance ID will be deleted when unregistering. Added some code to check registered with FCM and delete the token if so.
Related Issue
#2082
Motivation and Context
I need to refresh FCM token in certain scenarios. But unregistering and registering again returns the same token. But with this change FCM instance ID will be deleted when unregistered. If you try to send a push notification after unregistering, you will get an "Not registered" error from fcm end-point (which should be the correct behavior I guess).
How Has This Been Tested?
Tested on a iPhone 6 (OS version 11.4).
Positive scenario:
Registered/unregistered multiple times. Got a new ID every time as expected. Sent notifications to all tokens. Notifications to the active token worked. Rest failed with "Not registered".
Negative scenario:
error callback was called if no network connection during unregistering.
##Note
Please review the pull request carefully since I am a Objective C noob.