React native 在React本机iOS中显示自定义FCM推送通知

React native 在React本机iOS中显示自定义FCM推送通知,react-native,firebase-notifications,React Native,Firebase Notifications,我正在处理一个react本地项目,该项目希望接收FCM推送通知。我正在使用这个模块。我要做的是手动显示通知 在这个模块中,有一个函数 import {Platform} from 'react-native'; import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm'; FCM.on(FCMEvent.Noti

我正在处理一个react本地项目,该项目希望接收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设置应该是正确的,因为我可以收到通知。如果我使用键“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云消息传递的工作机制吗


非常感谢你

请使用以下代码获取FCM令牌,该令牌应在firebase中注册。成功注册后,您将收到“notif”中的远程通知

}))

FCM.on(FCMEvent.RefreshToken, (token) => {
    console.log("registration token:" + token);
// fcm token may not be available on first load, catch it here