iOS – Firebase Token Not Refreshed Automatically After App Reinstall or Update

SebastienC8 days ago

Hi,

I’m developing a custom iOS app based on Traccar Manager with Firebase Cloud Messaging (FCM) integration.

Everything works fine on first launch:
The FCM token is generated, correctly sent to Traccar through the notificationTokens user attribute, and push notifications are received.

However, I’ve noticed a problematic behavior:

If the user updates or reinstalls the iOS app, Firebase correctly generates a new token.
But this new token is not automatically updated in Traccar.

As a result, push notifications stop working.
The only way to make it work again is to manually log out and log back in to the app, which triggers the new token to be sent.

Is there a way to ensure the token is automatically updated in Traccar when it changes (via onTokenRefresh), even if the user is already logged in?

Thanks in advance for your help!

Sébastien

Anton Tananaev8 days ago

What version of the app are you using?

SebastienC8 days ago

Hi Anton,

Thanks for your quick reply!

I’m using version 6.5 of the app, and the server is running version 6.2.

Let me know if you need any additional info.

Best regards,

Anton Tananaev8 days ago

Traccar Manager doesn't have a 6+ version yet.

SebastienC8 days ago

Ah, my mistake, I thought you were referring to the web (server) version.

As for the iOS app, I’m using the latest version available on the Git, I downloaded it about 5 days ago.

Thanks again!

Anton Tananaev8 days ago

Which git repository?

SebastienC8 days ago

I’m using the official repository:
https://github.com/traccar/traccar-manager

I cloned it recently and integrated Firebase Cloud Messaging into the iOS project.

Anton Tananaev8 days ago

I believe this should solve the problem:

https://github.com/traccar/traccar-manager/commit/8d3ebcd0eddbd0b0bce1a49768617cc9ac226483

Please try and let us know.

SebastienC7 days ago

Hi Anton,

Thanks for the link!

I’ve already updated my project with the latest version of lib/main_screen.dart, and the code appears identical to the commit you shared.

Unfortunately, the issue still occurs:
If I update or reinstall the app, the FCM token is refreshed correctly by Firebase, but it's not updated in Traccar unless I manually log out and log back in.

So as it stands, unless the user explicitly logs out, push notifications stop working after a reinstall or update.

Let me know if you think there’s a better place to handle the token update.

Best regards,
Sébastien

Anton Tananaev7 days ago

Have you checked if the token update callback is called?

SebastienC6 days ago

Yes, I’ve checked, the token update callback is triggered, but the Firebase token doesn’t actually update in the user configuration unless I manually sign out and then sign back in.

Anton Tananaev6 days ago

And is the page fully loaded when it gets triggered? I don't see why it wouldn't be updated. We use exactly the same API call.