Android 使用React-Native fcm响应本机推送通知

Android 使用React-Native fcm响应本机推送通知,android,firebase,react-native,firebase-cloud-messaging,firebase-notifications,Android,Firebase,React Native,Firebase Cloud Messaging,Firebase Notifications,我正在尝试让推送通知显示在Nexus5(android 6.0.1)的通知托盘中。使用React-Native 0.42,React-Native CLI 2.0.1。我正在Ubuntu 14.04上开发 我用的是firebase。我进入我的控制台>通知>发送消息>特定设备(我从下面的remote debugging console.log获取) 我正在记录通知,正如您在代码中看到的,它们确实会进入我的设备,正如我在日志中看到的那样 但是,我不知道如何在通知栏中显示它们。通过查看文档和搜索论坛,

我正在尝试让推送通知显示在Nexus5(android 6.0.1)的通知托盘中。使用React-Native 0.42,React-Native CLI 2.0.1。我正在Ubuntu 14.04上开发

我用的是firebase。我进入我的控制台>通知>发送消息>特定设备(我从下面的remote debugging console.log获取)

我正在记录通知,正如您在代码中看到的,它们确实会进入我的设备,正如我在日志中看到的那样

但是,我不知道如何在通知栏中显示它们。通过查看文档和搜索论坛,它们似乎应该默认显示

componentDidMount() {
        FCM.requestPermissions(); // for iOS
        FCM.getFCMToken().then(token => {
            console.log(token)
            // store fcm token in your server
        });
        this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
          console.log(notif)

        });
});
似乎需要“自定义通知”才能在顶部托盘中显示通知。我将此添加到我的有效负载中:

“自定义通知”:{ “主体”:“测试主体”, “标题”:“测试标题”, “颜色”:“00ACD4”, “优先级”:“高”, “图标”:“ic_notif”, “组”:“组”, “id”:“id”, “在前景中显示”:真 }


因此,我认为应用程序必须接收通知,解析数据,并添加此自定义通知参数

您的构造函数中的以下内容如何:

FCM.requestPermissions(); // for iOS
FCM.getFCMToken().then(token => {
  console.log(token)
  // store fcm token in your server
});

this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
  // do some component related stuff
  console.log(notif);
  //alert(notif.fcm.body);

  FCM.presentLocalNotification({
    id: "UNIQ_ID_STRING",                               // (optional for instant notification)
    title: "My Notification Title",                     // as FCM payload
    body: notif.fcm.body,                    // 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
    big_text: "Show when notification is expanded",     // Android only
    sub_text: "This is a subText",                      // Android only
    color: "red",                                       // Android only
    vibrate: 300,                                       // Android only default: 300, no vibration if you pass null
    tag: 'some_tag',                                    // Android only
    group: "group",                                     // Android only
    picture: "https://google.png",                      // Android only bigPicture style
    ongoing: true,                                      // Android only
    my_custom_data: 'my_custom_field_value',             // extra data you want to throw
    lights: true,                                       // Android only, LED blinking (default false)
    show_in_foreground: true                                  // notification when app is in foreground (local & remote)
  });
});

FCM.subscribeToTopic('test_topic');

我也有同样的问题。。。您对此有任何解决方案吗?您必须使用FCM.presentLocalNotification()。因为如果您的应用处于活动状态,则通知处理由您负责,而如果应用处于非活动状态,则由手机自动显示