FCM令牌何时到期? [英] When does a FCM token expire?
本文介绍了FCM令牌何时到期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- - 应用程序删除实例ID -
- 该应用程序已在新设备上恢复
- - 用户卸载/重新安装应用程序
- - 用户清除应用程序数据。
$ b
监视器令牌生成
onTokenRefreshcallback在每次生成新的标记时触发,所以
在其上下文中调用getToken确保您正在访问
当前可用的注册标记。确保已经将
服务添加到您的清单中,然后在
onTokenRefresh的上下文中调用getToken,并如图所示记录值:
@Override
public void onTokenRefresh(){
//获取更新的InstanceID标记。
String refreshedToken = FirebaseInstanceId.getInstance()。getToken();
Log.d(TAG,Refreshed token:+ refreshedToken);
//如果您想发送消息到这个应用程序实例或
//在服务器端管理这个应用程序订阅,请将
// Instance ID令牌发送到您的应用程序服务器。
sendRegistrationToServer(refreshedToken);
}
When do FCM tokens expire? Is it at 6 months?
解决方案
it doesn't expire tho. it renews itself if one of the following happens.
- -The app deletes Instance ID
- -The app is restored on a new device
- -The user uninstalls/reinstall the app
- -The user clears app data.
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);
}
这篇关于FCM令牌何时到期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文