简体   繁体   English

Firebase 云消息传递:FCM 令牌到期

[英]Firebase Cloud Messaging : Expiration of FCM token

I understand that the FCM token renews itself if one of the following happens.我了解,如果发生以下情况之一,FCM 令牌会自行更新。

-The app deletes Instance ID - 应用删除实例ID
-The app is restored on a new device - 该应用程序在新设备上恢复
-The user uninstalls/reinstall the app - 用户卸载/重新安装应用程序
-The user clears app data. - 用户清除应用数据。

The following can be used at the App side to monitor Token renewal. App端可以使用下面的来监控Token更新。

Monitor token generation监控令牌生成

The onTokenRefreshcallback fires whenever a new token is generated, so calling getToken in its context ensures that you are accessing a current, available registration token.每当生成新令牌时 onTokenRefreshcallback 都会触发,因此在其上下文中调用 getToken 可确保您正在访问当前可用的注册令牌。 Make sure you have added the service to your manifest, then call getToken in the context of onTokenRefresh, and log the value as shown:确保您已将该服务添加到清单中,然后在 onTokenRefresh 的上下文中调用 getToken,并记录如下所示的值:

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // Instance ID token to your app server.
    sendRegistrationToServer(refreshedToken);
}

My question is, when the app is terminated, the token expires and there is no way for the FCM server to know what the new token is for the device (if exist).我的问题是,当应用程序终止时,令牌会过期并且 FCM 服务器无法知道设备的新令牌是什么(如果存在)。 So when I send a notification/data message to this device, the server fails to send it to the device as it doesn't know where to send it to (as there is no valid token).因此,当我向此设备发送通知/数据消息时,服务器无法将其发送到设备,因为它不知道将其发送到哪里(因为没有有效的令牌)。 How do I make sure that in such situations I can notify the device ?我如何确保在这种情况下我可以通知设备? I dont do a customer token generation.我不做客户令牌生成。 So the it seems to refresh the token now and then.所以它似乎不时刷新令牌。 How do I increase the validity of my token ?如何提高令牌的有效性?

You will need to check for an error when sending the message, and pay attention to the error codes, as listed in the documentation .您需要在发送消息时检查错误,并注意文档中列出的错误代码。 You should stop using the token if you get the error messaging/registration-token-not-registered .如果您收到错误messaging/registration-token-not-registered您应该停止使用该令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Firebase 云消息传递令牌 (FCM) 令牌太短/不完整 - Android Firebase Cloud Messaging Token (FCM) token is too short/incomplete 在FCM(Firebase云消息传递)中,在通知中包含令牌是否安全? - In FCM (Firebase cloud messaging), is it safe to include token in the notification? Firebase Cloud Messaging(FCM)注册令牌服务器端验证 - Firebase Cloud Messaging (FCM) registration token server-side validation 是一个设备还是一个帐户的FCM(firebase云消息传递)令牌? - Is FCM (firebase cloud messaging) Token for one device or for one account? 将 FCM(Firebase Cloud Messaging)令牌映射到自定义用户 ID - Mapping FCM(Firebase Cloud Messaging) Token to Custom UserID 如何向FCM(Firebase云消息传递)令牌的特定用户发送消息? - How to send a message to a specific user of an FCM (Firebase Cloud Messaging) token? Android,FireBase 云消息传递,(FCM) - Android, FireBase Cloud Messaging, (FCM) addCompleteListener()尚未解决-Firebase Cloud Messaging(FCM) - addCompleteListener() is not being resolved - Firebase Cloud Messaging (FCM) MismatchSenderId错误Firebase云消息传递(FCM) - MismatchSenderId error Firebase Cloud Messaging (FCM) Firebase Cloud Messaging(FCM)无法获取数据 - Firebase Cloud Messaging (FCM) not getting data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM