【发布时间】:2020-11-02 10:20:41
【问题描述】:
我将 react native push notification 与 firebase 一起使用。我收到通知,一切正常,但问题是 OnOpenNotfication 函数启动了两次。它第一次显示 {} 并自动调用自身。当我按下通知时,它也会触发并且什么都没有显示,我的意思是通知什么都没有。
但是我只想在单击通知时调用 onOpenNotification。而且我还想将用户从 onOpenNotfication 导航到特定屏幕,但它会自动启动,这就是为什么我不能
这是代码。
componentDidMount = async () => {
fcmService.registerAppWithFCM();
fcmService.register(onRegister, onNotification, onOpenNotification);
localNotificationService.configure(onOpenNotification);
function onRegister(token) {
console.log('[App] onRegister: ', token);
}
function onNotification(notify) {
console.log('[App] onNotification: ', notify);
const options = {
soundName: 'default',
playSound: true, //,
// largeIcon: 'ic_launcher', // add icon large for Android (Link: app/src/main/mipmap)
// smallIcon: 'ic_launcher' // add icon small for Android (Link: app/src/main/mipmap)
};
localNotificationService.showNotification(
0,
notify.title,
notify.body,
notify,
options,
);
}
function onOpenNotification(notify) {
console.log('[App] onOpenNotification: ', notify);
alert('Open Notification: ' + notify.body);
}
};
【问题讨论】:
标签: react-native react-native-firebase react-native-push-notification