WorryFree Computers   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix an issue that delete token does not trigger token refresh notification or delegate #5339

Merged
merged 8 commits into from
Apr 13, 2020

Conversation

charlotteliang
Copy link
Contributor
@charlotteliang charlotteliang commented Apr 10, 2020

Fix #5338: When a token is deleted by calling deleteToken method, messaging doesn't trigger FIRMessagingRegistrationTokenRefreshedNotification notification or calling the FIRMessagingDelegate messaging:didReceiveRegistrationToken: method.

Hence the token parameter in the delegate API messaging:didReceiveRegistrationToken:should be nullable, a change we might need to get in the next breaking change API.

Update:
I also cleanup the code and realize IID send out two notifications (kFIRInstanceIDDefaultGCMTokenNotification, kFIRInstanceIDTokenRefreshNotification) when fcm token is updated. Sometimes it calls one, while other time it calls the other. These two notifications are essentially doing the exactly the same thing. So I replaced one that is not in the public API of IID.

Note: I was trying out combine with FIRMessagingRegistrationTokenRefreshedNotification and want to use token refresh notification/delegate to update the environment variable identity to reflect on UI on demand rather than manual update, then I discover this issue.

Copy link
Member
@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Description says "Fix #5338", GitHub will automatically close the associated issue when this PR merges. Maybe it also does with "Issue", but I'm not sure ...

Firebase/Messaging/FIRMessaging.m Outdated Show resolved Hide resolved
Copy link
Contributor
@morganchen12 morganchen12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the breaking API change can be factored out of this PR and submitted separately.

@charlotteliang
Copy link
Contributor Author

yeah, I left the public API header change out of this PR.

@charlotteliang
Copy link
Contributor Author

I will kick out a separate PR for the integration test for this as we have configuration needs to be done.

@charlotteliang charlotteliang merged commit c049f74 into master Apr 13, 2020
@charlotteliang charlotteliang deleted the messaging-swifting branch April 13, 2020 23:32
print("Failed to get FID: ", error)
return
}
self.instanceID = fid ?? "None"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be nil if it doesn't exist, right? Otherwise consumers of this could think that an instanceID is available but the String is actually "None" which isn't valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Good catch!

Comment on lines +39 to +43
_ = NotificationCenter.default
.publisher(for: Notification.Name.MessagingRegistrationTokenRefreshed)
.map { $0.object as? String }
.receive(on: RunLoop.main)
.assign(to: \Identity.token, on: identity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you'll need to store these AnyCancellable values returned somewhere, likely in a Set<AnyCancellable> otherwise the subscription will only last the lifetime of this code block.


// Subscribe to fid changes
_ = NotificationCenter.default
.publisher(for: Notification.Name.FIRInstallationIDDidChange)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh - looks like we need to change the API name here as well (shouldn't have a FIR prefix).

Comment on lines +51 to +58
Installations.installations().installationID(completion: { fid, error in
if let error = error as NSError? {
print("Failed to get FID: ", error)
return
}
self.identity.instanceID = fid ?? "None"
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the notification not include information about the FID? If not we should look at adding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ryanwilson pushed a commit that referenced this pull request Apr 24, 2020
@firebase firebase locked and limited conversation to collaborators May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete token doesn't trigger token refresh notification and delegate
6 participants