-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Delete FCM instanceID when unregistering - iOS #2509
base: master
Are you sure you want to change the base?
Conversation
Added code to delete Firebase token when unregistering in iOS
| NSLog(@"unsubscribe from topic: %@", topic); | ||
| [pubSub unsubscribeFromTopic:topic]; | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Let me do that.
I do not know how APNS token works. Thats why I put inside an else. hehe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@macdonst
Are the changes ok?
PushInstanceIDListenerService doesn't have to be exported. So explicitly set the exported value to false
Update plugin.xml
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.