React Native 推送通知本地通知未显示在真实设备上

问题描述

我按照 https://github.com/zo0r/react-native-push-notification 的指南在应用中启用云消息传递功能。在幕后,我使用的是 react-native-firebase。在开发过程中,我不得不根据从自定义后端服务器收到的云消息触发本地通知。

但是,该应用程序没有在系统托盘中弹出任何本地通知,但我可以看到该应用程序正在接收通知并在后台更新数据。在文档中,我看到我们需要创建一个通道来在托盘中弹出通知。我创建了频道并调用了本地通知。不幸的是,它没有奏效。

请检查下面的代码以触发基于云远程消息的通知。

“我可以在后台收到通知,但托盘中没有向用户显示通知”

    //Background handler
    messaging().setBackgroundMessageHandler(async remoteMessage => {
      //Trigger a local notification when app is offline
      LocalNotification(remoteMessage["data"]["id"]);
      this.updateData();
    });

并且本地通知是从文件中触发的。

import PushNotification from 'react-native-push-notification'

export const LocalNotification = (data) => {
  console.log("Triggering a local notif")
  
  PushNotification.createChannel({
      channelId: "mychannel",// (required)
      channelName: "My channel",// (required)
      vibrate: true,},(created) => {
    PushNotification.localNotification({
      channelId: "mychannel",autoCancel: true,bigText: data,subText: 'Notification',title: 'New notification received',message: `Notif ID: ${data}`,vibrate: true,vibration: 300,playSound: true,soundName: 'default',ignoreInForeground: false,importance:'high',invokeApp:true,allowWhileIdle: true,priority:'high',visibility:'public'
    })
  })
}

请在下方评论以获取任何额外信息。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)