【问题标题】:react-native-notification foreground messagesreact-native-notification 前台消息
【发布时间】:2020-09-11 02:18:12
【问题描述】:

大家好

我使用库 wix/react-native-notifications

看起来我的 android 出了点问题(ios 工作正常)。 对我来说:

  • registerRemoteNotificationsRegistered
  • registerRemoteNotificationsRegistered
  • registerNotificationOpened
  • getInitialNotification

干得好。

但是:

  • registerNotificationReceivedForeground
  • registerNotificationReceivedBackground

从未触发过。

我认为我在 AndroidManifest.xml 中放了一些错误(我尝试了不同的变体,但它仍然不起作用)。

或使用时出现问题

  • 反应原生通知
  • react-native-pusher-push-notifications

同时。

请问有人有什么想法吗?

我用:

  • "react-native-notifications": "^3.2.2",
  • “react-native-pusher-push-notifications”:“^2.4.0”,
  • “反应”:“16.9.0”,
  • "react-native": "0.61.5",

AndroidManifest.xml 中我认为可能有误的部分:

<service
  android:name=".java.MyFirebaseMessagingService"
  android:exported="false"
>
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT"/>
  </intent-filter>
</service>

【问题讨论】:

    标签: android react-native pusher velo react-native-notifications


    【解决方案1】:

    你可以通过这种方式在React Native中在前台接收Push Notification

    import {firebase} from '@react-native-firebase/messaging'
    import PushNotification from "react-native-push-notification";
    
     useEffect(()=>{notification()},[])
    
    const notification = () => {
        const messaging=firebase.messaging;
        const unsubscribe = messaging().onMessage(async remoteMessage => {
          console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
    
            PushNotification.localNotification({
                channelId: "reminder",
                message: remoteMessage.notification.body,
                title: remoteMessage.notification.title,
                bigPictureUrl: remoteMessage.notification.android.imageUrl,
                smallIcon: remoteMessage.notification.android.imageUrl,
            });
        });
        return unsubscribe;
    }
    

    【讨论】:

      【解决方案2】:

      好的,也许它会对某人有所帮助或只是开始一些讨论)

      好吧,据我了解,react-native-pusher-push-notifications 首先处理通知,所以库 react-native-notifications 无法捕捉到。

      不是更好的决定,但在我找到更好的解决方案之前它会起作用。

      我修改了react-native-pusher-push-notifications 库中的文件PusherWrapper.java 以处理更多信息。主要问题是库不返回在data 部分通知中发送的信息。

      【讨论】:

      • 哈,看起来有人已经面临缺乏额外信息的问题51
      猜你喜欢
      • 2017-12-29
      • 2020-07-03
      • 2022-12-30
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多