我正在做一个想要接收FCM推送通知的react原生项目。我使用的是react-native-fcm模块。我想要做的是手动显示通知。
在此模块中,有一个函数
import {Platform} from 'react-native';
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm';
FCM.on(FCMEvent.Notification, async (notif) => {
console.log(notif);
});其中'notif‘应该是由设备接收的消息。但是,当通知发送到设备时,我无法接收到从未调用过的console.log(notif);。
我想要做的是使用以下函数通过手动处理notif json来显示通知。
FCM.presentLocalNotification({
id: "UNIQ_ID_STRING", // (optional for instant notification)
title: "My Notification Title", // as FCM payload
body: "My Notification Message", // as FCM payload (required)
sound: "default", // as FCM payload
priority: "high", // as FCM payload
click_action: "ACTION", // as FCM payload
badge: 10, // as FCM payload IOS only, set 0 to clear badges
number: 10, // Android only
ticker: "My Notification Ticker", // Android only
auto_cancel: true, // Android only (default true)
large_icon: "ic_launcher", // Android only
icon: "ic_launcher", // as FCM payload, you can relace this with custom icon you put in mipmap
});我还意识到,为FCM发送的消息也会影响模块显示消息的方式。有关详细信息,请查看FCM。
我想我的FCM设置应该是正确的,因为我可以收到通知。如果我发送带有key "notification"的消息,我的react原生应用程序可以收到通知。像这样:
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
}但是前一个函数中的console.log(notif);仍然没有被调用。
我还尝试用有效负载发送通知。
"data" : {
"title" : "Mario",
"body" : "PortugalVSDenmark"
}但是console.log(notif);仍然没有被调用。
有人知道react-native-fcm和firebase-cloud-messaging的工作机制吗?
非常感谢!
https://stackoverflow.com/questions/47710841
复制相似问题