Skip to content

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

Closed
@chwo

Description

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!

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions