我在我的 RN 应用程序中使用 react-native-fcm 组件来推送通知。它运行良好,但我注意到一个让我发疯的问题,当我们在 Play 商店发布新版本并且应用程序更新时令牌过期,我们已经保存了旧令牌并向该 fcm 令牌发送通知,所以用户停止接收通知。
如果用户注销并再次登录,我会得到新的令牌,但当然我不能强迫我的用户这样做,在组件示例中,我发现了一个刷新令牌事件但它不起作用,你知道为什么会发生这个事件吗?刷新时没有收到新令牌?我做错了什么?谢谢。
这是我的代码(为了便于阅读,我删除了一些部分):
import React, { Component } from 'react';
import { ScrollView, View, Text, Linking, TouchableOpacity, AppState } from 'react-native';
import { connect } from 'react-redux';
import FCM, { FCMEvent } from 'react-native-fcm';
import { getTopNotification, updateUser } from '../api';
import { topNotificationChanged, logOut } from '../actions';
class Home extends Component {
constructor() {
super();
this.onLogOutPress.bind(this);
}
state = { topNotificationLink: '', appState: AppState.currentState };
componentDidMount() {
AppState.addEventListener('change', this.handleAppStateChange);
this.refreshTokenListener = …Run Code Online (Sandbox Code Playgroud)