FCM 令牌何时到期?

When does a FCM token expire?(FCM 令牌何时到期?)
本文介绍了FCM 令牌何时到期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FCM 令牌何时到期?是6个月吗?

解决方案

不过它不会过期.如果发生以下情况之一,它会自行更新.

根据 https://firebase.google.com/docs/cloud-消息传递/android/客户端:

  1. -应用删除Instance ID
  2. -应用在新设备上恢复
  3. -用户卸载/重新安装应用程序
  4. -用户清除应用数据.

<块引用>

监控令牌生成

每当生成新令牌时都会触发 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:

  1. -The app deletes Instance ID
  2. -The app is restored on a new device
  3. -The user uninstalls/reinstall the app
  4. -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);
}

EDIT

onTokenRefresh() is now deprecated. onNewToken() should be used instead.

这篇关于FCM 令牌何时到期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)