标签: react-native-push-notification

当应用程序处于后台时,React Native 处理套接字连接的事件?

我正在使用 React Native 开发聊天应用程序,并且WebSocket在活动模式下一切正常,但是当您按下主页按钮使应用程序处于后台模式时,WebSocket不会触发 onMessage 事件功能

好消息是WebSocket连接仍然连接但未触发事件功能。

我只想在后台模式下收到消息时推送通知。

我做了一项研究,发现我需要始终运行无声的背景音轨(有人说这是非法的方式)。

是否有合法的 API 可以在后台保持连接活跃?

后台模式需要重新连接socket连接吗

我的代码

events = (data) =>{

    if(data[0].message){
          if(this.state.appState !== 'active'){
             console.log('check here') // not working when the app in background mode
              PushNotification.localNotification({// not working when the app in background mode
                    message: data[0].message, 
                    number: 1,
                    title: 'a new message from: '+data[0].username,

                });
            }else{
                this.setState({messages: data[0]})
            }
    }
}


socketConnect = () =>{
        AsyncStorage.getItem('token').then((token) => {
        let connection = new wamp.Connection({ url: 'wss://*******/',
            realm: …
Run Code Online (Sandbox Code Playgroud)

android websocket ios react-native react-native-push-notification

8
推荐指数
1
解决办法
5658
查看次数

Android:当应用关闭并点击通知时,'onNotification'不会执行

我正在使用react-native-pushnotification.这里是模块链接 https://github.com/zo0r/react-native-push-notification 在ios通知工作正常,在后台和前台也工作,但在android前台它工作正常,但在后台我收到通知,当点击该通知应用程序重新启动并且没有在android中显示任何警报时,

  1. 在iOS中,这些功能正常运行.但在android我面临这个问题

任何人都可以给我一些建议,如何解决它,任何帮助非常感谢.

react-native react-native-push-notification

7
推荐指数
1
解决办法
248
查看次数

当应用程序在后台或关闭时,本机推送通知不显示横幅(在屏幕上弹出)

我正在使用react-native-push-notification并遵循其文档。当应用程序位于前台时,它工作正常,但是当应用程序位于后台时,我尝试从Firebase控制台发送通知,只是在状态栏中显示了该应用程序的一个小图标,但未显示横幅

我试图添加一个新频道,但仍然无法正常工作 aa

componentDidMount() {

        NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange);

        PushNotification.configure({

            // (optional) Called when Token is generated (iOS and Android)
            onRegister: function(token) {
                console.log( 'TOKEN:', token );
            },

            // (required) Called when a remote or local notification is opened or received
            onNotification: function(notification) {
                console.log( 'NOTIFICATION:', notification );

                Platform.OS === 'ios' ? notification.finish(PushNotificationIOS.FetchResult.NoData) : null;
            },

            // ANDROID ONLY: GCM or FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications)
            senderID: …
Run Code Online (Sandbox Code Playgroud)

firebase react-native firebase-cloud-messaging react-native-push-notification

7
推荐指数
1
解决办法
473
查看次数

WARN 没有为 React Native 中的关键 ReactNativeFirebaseMessagingHeadlessTask 注册任务?

react-native Firebase我使用和创建了推送通知react-native-push-notification。我已经实现了所有类型的通知,例如本地通知、计划背景通知和退出通知。但当我的应用程序处于退出状态时,我已通过FCM发送了推送通知。所以我在控制台上显示了一条警告,即WARN No task Registration for key ReactNativeFirebaseMessagingHeadlessTask。那我该如何解决呢。

代码:

import React, {Fragment, useEffect} from 'react';
import {StyleSheet, View, Text, Button} from 'react-native';
import PushNotification from 'react-native-push-notification';

import messaging from '@react-native-firebase/messaging';

//1
const checkPermission = () => {
  messaging()
    .hasPermission()
    .then((enabled) => {
      if (enabled) {
        getToken();
      } else {
        requestPermission();
      }
    })
    .catch((error) => {
      console.log('error checking permisions ' + error);
    });
};

//2
const requestPermission = () => {
  messaging()
    .requestPermission()
    .then(() …
Run Code Online (Sandbox Code Playgroud)

react-native firebase-cloud-messaging react-native-firebase react-native-push-notification

7
推荐指数
1
解决办法
2万
查看次数

React-native:使用 zo0r/react-native-push-notification 显示前台通知,如后台通知

我已经使用zo0r / react-native-push-notification在我的 React-native 应用程序上设置了推送通知。当应用程序处于后台模式时,它适用于 Android 和 iOS。

但是,当应用程序处于 iOS 的前台模式时,不会显示通知。我知道我必须在前台模式下处理通知,但我想以与后台模式下完全相同的方式显示它们。

所以我做了以下事情:

import {PushNotificationIOS} from 'react-native';

PushNotification.configure({
...
   onNotification: function(notification) {
      if (notification.foreground) {
         PushNotification.localNotification(notification);
      }
      notification.finish(PushNotificationIOS.FetchResult.NoData);
   },
...
}
Run Code Online (Sandbox Code Playgroud)

但是没有任何反应,通知仍然没有显示,我错过了什么?

push-notification apple-push-notifications ios react-native react-native-push-notification

6
推荐指数
1
解决办法
4573
查看次数

如何更改反应本机推送通知状态栏图标?

我正在使用firebase并将react-native-push-notification通知推送到我的Android应用程序,并努力用我自己的图标更改小通知图标,并且有关此主题的任何线程似乎都没有帮助。ic_test.png我的文件夹中有以下元数据声明@mipmap,但 Android 清单中的这些元数据声明都不起作用:

1. xml <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_test" />

2. xml <meta-data android:name="com.dieam.reactnativepushnotification.notification_icon" android:resource="@mipmap/ic_test" />

不过,我可以通过添加元数据来更改图标的颜色:

<meta-data  
  android:name="com.dieam.reactnativepushnotification.notification_color"
  android:resource="@android:color/white"
/>
Run Code Online (Sandbox Code Playgroud)

情况:

在此输入图像描述

在此输入图像描述

有什么想法我可能在这里做错了吗?

编辑:

通过不在清单中设置任何图标元数据资源,使其适用于本地通知。我刚刚设置了以下元数据资源

<meta-data  
  android:name="com.dieam.reactnativepushnotification.notification_color"
  android:resource="@android:color/MY_COLOR"
/>
Run Code Online (Sandbox Code Playgroud)

更改图标的背景颜色。

另外,设置以下键值对

PushNotification.localNotification({...parameters, smallIcon: 'ic_test'});
Run Code Online (Sandbox Code Playgroud)

触发本地通知时。

编辑:

我正在使用Firebase Cloud Messaging 旧版 HTTP 协议,并将icon参数设置为"ic_test"似乎也不起作用。

android push-notification react-native react-native-push-notification

6
推荐指数
1
解决办法
7260
查看次数

反应原生推送通知显示在 android 的控制台上,但不在设备或模拟器上显示通知

我正在使用 FCM 在 react native android 上推送通知,但问题是我能够接收通知并且它出现在控制台上,但未显示在设备或模拟器上。

我的代码如下

componentDidMount(){
  PushNotification.configure({

        onRegister: function (token) {
            console.log('TOKEN:', token);
        },

        onNotification: function (notification) {
            console.log('NOTIFICATION:', notification);

            //I AM ABLE TO SEE THE CONSOLE LOG BUT NOTIFICATION DOESN'T APPEAR ON THE DEVICE
        },

        senderID: "",

        permissions: {
            alert: true,
            badge: true,
            sound: true
        },

        popInitialNotification: true,

        requestPermissions: true,
    });
}
Run Code Online (Sandbox Code Playgroud)

android push-notification react-native firebase-cloud-messaging react-native-push-notification

5
推荐指数
1
解决办法
686
查看次数

警报未显示....单击推送通知时

我正在运行示例应用程序.....我正在使用模块进行推送通知.....我的问题是在清除应用程序实例后单击推送通知时...在onNotification()控制台上打印但是警报没有显示....甚至试图保持警报的时间,但它不起作用.....这是一个问题是获得唯一的iOS .......请给出任何建议. ......

onNotification: notification => {
    console.log('NOTIFICATION:', notification)
        if(notification.notificationType === XXX){
         alert('NOTIFICATION:'+JSON.stringify(notification))
         }
   }
Run Code Online (Sandbox Code Playgroud)

react-native react-native-push-notification

5
推荐指数
0
解决办法
187
查看次数

React Native 本地/远程推送通知:如何使用有效负载获取点击/触摸事件?

我使用React Native开发了一个跨平台混合应用程序。

我通过 Amazon SNS集成了远程推送通知。

我尝试了很多插件,但主要是zo0r/react-native-push-notification

通知到达 Android 手机并立即执行“onNotification”回调。(ios手机我还没试过)

没关系,但不是我需要的。

无论应用程序的状态是什么(在前台、后台或关闭),我都想在用户触摸通知时获取点击/触摸事件。

需要通知的有效负载来打开应用程序中应引导用户访问的合适的 Web 视图。

我尝试处理远程通知并推送新的本地通知,但我没有得到我正在寻找的事件。

android push-notification react-native react-native-push-notification

5
推荐指数
0
解决办法
499
查看次数

如何在react-native项目中检查google play services版本和firebase版本?

我正在尝试安装 rn-push-notifications,我需要 google play services 版本和 firebase 版本。你能帮我一下吗?

javascript react-native react-native-push-notification react-notifications

5
推荐指数
2
解决办法
7671
查看次数