Push notification token gets invalidated after few days b/111760840
Describe your environment
- Xcode version: 9.4.1
- Firebase SDK version: 5.0.0
- Firebase Component: Firebase Messaging
- Component version: 3.0.0
Describe the problem
Token gets invalidated after few days with no clear reason.
Steps to reproduce:
- Register token, send token to server
- Close app, wait for 2-3 days.
- Send push notification to the registered token
- Gets token unregistered.
From the documentation, it says: A previously valid registration token can be unregistered for a variety of reasons, including:
- The client app unregistered itself from FCM. How is this possible? I don't think this is the issue.
- The client app was automatically unregistered. This can happen if the user uninstalls the application or, on iOS, if the APNS Feedback Service reported the APNS token as invalid. We didn't make any changes to certificate and did not uninstall app.
- The client app was updated, but the new version is not configured to receive messages. No changes here.
- The registration token expired. For example, Google might decide to refresh registration tokens or the APNS token may have expired for iOS devices. I think this is the issue, but it's not making any sense. 07/12/18 - Refresh token received, then close app 07/14/18 - Send push notification, gets token is unregistered, no notification received. 07/16/18 - Send push notification from same token, gets token unregistered, no notification received 07/16/18 - Open app, refresh token received 07/16/18 - Send push notification 07/16/18 - Successfully getting the push notification.
@morganchen12
- Can you share particulars on how your notifications are delivered and how token refresh is handled? Relatively frequent token refresh is normal and not likely to be a source of bugs, but your client needs to make sure it's handling token refresh appropriately.
We send the notification via the FCM API, and upon token refresh we update the token on our server. We didn't notice issue until recently. Previously, the token refresh seems to happen once a month or so. Now it happened really frequently. What changes?
- On notification expiration Instance ID will normally generate a new token, so FCM sends won't fail. I'm not sure how often tokens are refreshed (@chliangGoogle may know).
The token gets invalidated really quickly. The user shouldn't be expected to open the app everyday. From my logs, it got invalidated after 2 days.
TIA
Can you share your project ID? This looks like a backend issue and may require looking at your Firebase project information.
@morganchen12 What is your email?
Instead of emailing me directly, you should file a support ticket so we can keep all your debugging-related nonpublic information in one place (the ticket can link to this GH issue).
Apologies for the misdirection, I realize this is really obtuse after asking you to file a separate issue.
@morganchen12 I filed a support ticket. let me know if you need any additional information. Thank you!
@morganchen12 I monitor the token I got from yesterday, and today it says it's NotRegistered. This is really bad.
@morganchen12 Did you get the info needed from the support ticket? I sent it out a week ago, but no update there. I also tried to update to the latest SDK and the token still gets invalidated after 3 days (without opening the app after the token was generated)
I haven't seen it. Can you email me your project directly? I'm morganchen@
Filed a bug with the backend team, I'll keep this ticket updated. b/111760840
@richardliveraise can you share one or more tokens that were unregistered early?
@morganchen12 I sent them to your email. thanks!
Looks like your tokens are being replaced, while still valid, by new tokens. Can you send a currently valid token? This way we can check what's causing it to be refreshed while still valid.
@morganchen12 I sent the valid token to your email. Thank you!
Do you know when this started happening?
Not sure yet. It looks like your app is sending up frequent requests to register a new token, though this may not be the root cause of the issue (since your app has always been doing this and this has only been an issue recently).
Can you pin down any repro steps for this issue or share your codebase?
@morganchen12 Which request do you mean? Is it [[UIApplication sharedApplication] registerForRemoteNotifications]; ? I tried calling this multiple times, but the delegate returns the same token. If the app is open and new token is generated, It will send the new token to the backend, so it's not an issue.
The app is not active when the token gets invalidated, so there shouldn't be any request made. Can you share with me what are the triggers/flows that cause the token to be refreshed? Maybe I can try debug it on my end too.
Thanks!
Do you have any explicit calls to InstanceID in your code?
@morganchen12 No, I dont. Should I?
From the docs, "Either at startup, or at the desired point in your application flow, register your app for remote notifications"
From the sample code, this code is called every time app is launched.
What are the triggers that cause the token to be refreshed on your end?
You don't need any explicit calls to the InstanceID API. Let me check and I'll get back to you on the second question.
Looks like there's nothing wrong going on in your code. Are you able to reproduce this with the Messaging quickstart repo? Also, can you send the logs of your app lifecycle with -FIRDebugEnabled on?