FCM 令牌何时到期?是6个月吗?
不过它不会过期.如果发生以下情况之一,它会自行更新.
根据 https://firebase.google.com/docs/cloud-消息传递/android/客户端:
<块引用>
监控令牌生成
每当生成新令牌时都会触发 onTokenRefreshcallback,因此在其上下文中调用 getToken 可确保您正在访问一个当前可用的注册令牌.确保您已添加服务到您的清单,然后在上下文中调用 getTokenonTokenRefresh,并记录如下所示的值:
@Override公共无效 onTokenRefresh() {//获取更新的 InstanceID 令牌.字符串 refreshedToken = FirebaseInstanceId.getInstance().getToken();Log.d(TAG, "刷新令牌:" + refreshedToken);//如果要向此应用程序实例发送消息或//在服务器端管理此应用订阅,发送//实例 ID 令牌到您的应用服务器.sendRegistrationToServer(refreshedToken);}
编辑
onTokenRefresh() 现在已弃用.onNewToken()<应该使用/a>.
When do FCM tokens expire? Is it at 6 months?
It doesn't expire though. It renews itself if one of the following happens.
According to https://firebase.google.com/docs/cloud-messaging/android/client:
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. Make sure you have added the service to your manifest, then call getToken in the context of onTokenRefresh, and log the value as shown:
@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);
}
EDIT
onTokenRefresh() is now deprecated. onNewToken() should be used instead.
这篇关于FCM 令牌何时到期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!