Skip to content

fix: return cached token on iOS until APNs token is available - #33

Closed
qaysdwekat wants to merge 1 commit into
mainfrom
qais/FM-968-wait-for-apns-token
Closed

qaysdwekat wants to merge 1 commit into
mainfrom
qais/FM-968-wait-for-apns-token

Conversation

@qaysdwekat

Copy link
Copy Markdown

On iOS, getToken() called Messaging.token() before APNs delivered the device token, which fails with FCM error 505 (Sentry FAMEDLY-APP-A7T, mostly background launches).

Now, while apnsToken is nil, it returns the cached fcmToken (or null) and registers for remote notifications. Once APNs is ready, Firebase fetches the token and delivers it via onNewToken, as getToken()'s docs describe.

Tested in the famedly app on an iOS simulator: normal init, plus a forced null on the first call, which takes the wait-for-onNewToken path.

getToken() called Messaging.token() before APNs delivered the device
token, which fails with FCM error 505. Return the cached token (or null)
instead; the new token arrives via onNewToken once APNs is ready.

Fixes FAMEDLY-APP-A7T
Refs: FM-968

Signed-off-by: Qays Dwekat <q.dweekat@famedly.com>
@qaysdwekat
qaysdwekat force-pushed the qais/FM-968-wait-for-apns-token branch from 3a3ce13 to fe8e6ac Compare October 29, 2026 08:08
if Messaging.messaging().apnsToken == nil {
UIApplication.shared.registerForRemoteNotifications()
result(Messaging.messaging().fcmToken)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does not actually fix it. The bug is that if I await getToken() in dart, then I expect that it waits until the apns token is registered and then returns the fcm token. But this instead returns null and how should I then know that I have to wait for the other endpoint?

@td-famedly

Copy link
Copy Markdown
Member

moved to #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants