react-native-onesignal接收推送通知而不打开通知 [英] react-native-onesignal receive push notification without opening notification

查看:270
本文介绍了react-native-onesignal接收推送通知而不打开通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查了 react-native-onesignal github自述文件,这似乎是唯一的方法要获取通知,请通过 onNotificationOpened()回调打开

I have checked react-native-onesignal github README and it seems the only way to get the notification is to open which is through the onNotificationOpened() callback.

他们的文档指出:

打开或接收到任何通知时,调用回调onNotification传递带有通知数据的对象.

When any notification is opened or received the callback onNotification is called passing an object with the notification data.

但是onNotification显然不起作用.

有什么方法可以获取通知而无需打开推送通知或启用应用内警报通知?

Is there any way to get the notification without opening the push notification or enabling the in-app alert notification?

推荐答案

关于NotificationExtenderService在android中的实现(未回答原始问题,而是@ryeballar提出的问题),如

Regarding implementation of NotificationExtenderService in android (not answering the original question, but the question asked by @ryeballar), as explained in https://documentation.onesignal.com/docs/android-customizations#section-background-data-and-notification-overriding:

  • 我在未实现NotificationExtenderService
  • 的情况下关闭/滑动/未启动应用程序时收到通知
  • 但是,要实现NotificationExtenderService,您需要执行以下操作(如上面引用的onesignal文档中所述,请注意,这里有一个错字,下面对此进行了修正):

  • I am getting notifications when the app is closed/swiped-out/not-started without implementing NotificationExtenderService
  • However, in order to implement NotificationExtenderService you need to do the following (as described in the onesignal documentation referenced above, note that there is a typo there, fixed below):

  1. node_modules\react-native-onesignal\android\src\main\java\com\geektime\rnonesignalandroid中创建一个名为NotificationExtender.java的文件,其内容如下:
  1. Create a file called NotificationExtender.java in node_modules\react-native-onesignal\android\src\main\java\com\geektime\rnonesignalandroid, with the following contents:

.

import com.onesignal.OSNotificationPayload;
package com.geektime.rnonesignalandroid;
import com.onesignal.OSNotificationPayload;
import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;
import com.onesignal.OSNotificationReceivedResult;

public class NotificationExtender extends NotificationExtenderService {
   @Override
   protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
        // Read properties from result.

      // Return true to stop the notification from displaying.
      return false;
   }
}

  1. 将以下内容添加到android\app\src\main\AndroidManifest.xml:

.

<service android:name=".NotificationExtender" 
   android:permission="android.permission.BIND_JOB_SERVICE" 
   android:exported="false">
  <intent-filter>
    <action android:name="com.onesignal.NotificationExtenderService" />
  </intent-filter>
</service>

  1. 重建您的应用

这篇关于react-native-onesignal接收推送通知而不打开通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆