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

FCM registration token is nil at first app start after update to sdk version 10.19.0 #12245

Closed
chwo opened this issue Jan 5, 2024 · 3 comments · Fixed by #12246
Closed

FCM registration token is nil at first app start after update to sdk version 10.19.0 #12245

chwo opened this issue Jan 5, 2024 · 3 comments · Fixed by #12246
Assignees

Comments

@chwo
Copy link

chwo commented Jan 5, 2024

Description

Actual behavior

Accessing the fcm token via Messaging.messaging().fcmToken at first app start after update to sdk version 10.19.0 is nil and does not return the previous fcm token immediately. Only after the messaging:didReceiveRegistrationToken: delegate callback the fcm token is available again.

The reason for this seems to be the change to NSSecureCoding for the internal classes which was done in this sdk version. #12075 #12110
Maybe it is related to the parsing changes in FIRMessagingTokenInfo.m which do not seem to be backwards compatible when decoding the previous value in the first session after the update (resulting in the nil return, see diff).

Expected behavior

From the docs:

The FCM registration token is sometimes refreshed automatically. In your Messaging delegate, the delegate method messaging(_:didReceiveRegistrationToken:) will be called once a token is available, or has been refreshed. Typically it should be called once per app start, but may be called more often if the token is invalidated or updated.

Token invalidation/update is not the case, since the app installation did not change and the fcm token stays the same.
So accessing the fcm token via Messaging.messaging().fcmToken should be immediately available and return the current fcm token. This should not be impacted and change behavior by updating the sdk version.
To clarify, this is change in behavior is only happening in the first session with this sdk version, in subsequent sessions it is immediately available again. In previous sdk updates the fcm token was immediately available also in the first session.

Reproducing the issue

Steps to reproduce

  • Create a sample app and configure Firebase Cloud Messaging
  • Access the fcm token at app start. E.g. print(Messaging.messaging().fcmToken) in application(_:didFinishLaunchingWithOptions:)
  • Make sure to use a previous sdk version first and run the app to enable/configure notifications (e.g. version 10.17.0)
  • Update the sdk version to version 10.18.0 or lower
  • Restart the app -> this prints the current fcm token ✅
  • Update the sdk version to 10.19.0 or higher
  • Restart the app -> the printed fcm token is nil ❌

Firebase SDK Version

10.19

Xcode Version

15

Installation Method

Swift Package Manager

Firebase Product(s)

Messaging

Targeted Platforms

iOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@chwo
Copy link
Author

chwo commented Jan 5, 2024

@paulb777 Mentioning you since you were involved with the changes in #12110

@paulb777
Copy link
Member

paulb777 commented Jan 5, 2024

@chwo Thanks for the very detailed report and analysis. We'll investigate.

@paulb777 paulb777 self-assigned this Jan 5, 2024
@paulb777 paulb777 added this to the 10.20.0 - M142 milestone Jan 5, 2024
@firebase firebase locked and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants