【发布时间】:2020-07-28 08:31:36
【问题描述】:
我正在尝试使用 react-native-firebase 在前台使用 react-native-firebase 捕捉通知。
如果应用程序在后台,通知只会显示一次(显然是因为它没有在应用程序内处理)。但是当应用程序在前台时,捕获通知的回调函数会以非常随机的方式多次触发。如果我刷新应用然后再次发送,通常这个数字会成倍增长,可以达到 12 倍或更多。
我非常简单的代码:
import React, { Component } from 'react';
import {
View,
Text,
} from 'react-native';
import messaging from '@react-native-firebase/messaging';
class App extends Component {
async componentDidMount() {
messaging().onMessage(async message => console.log("message received!!!")
}
render(){
return (
<View>
<Text>Notification App</Text>
</View>
)
}
}
export default App;
为了发送通知,我使用 Firebase 云消息测试系统:
我知道我的 FCM 令牌 ID,所以很容易。我的问题是如何让回调函数 messing().onMessage 只触发一次
【问题讨论】:
标签: react-native react-native-firebase