[英]react-native-onesignal receive push notification without opening notification
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. 我检查了react-native-onesignal github自述文件,看来获取通知的唯一方法是通过onNotificationOpened()回调打开。
Their documentation stated that: 他们的文件说明:
When any notification is opened or received the callback
onNotification
is called passing an object with the notification data.当打开或接收任何通知时,调用
onNotification
回调,传递带有通知数据的对象。
But onNotification
clearly does not work. 但
onNotification
显然不起作用。
Is there any way to get the notification without opening the push notification or enabling the in-app alert notification? 有没有办法在不打开推送通知或启用应用内警报通知的情况下获取通知?
The onNotification
function will only be called when opening a notification or when one is received while the app is in focus. 仅在打开通知时或在应用程序处于焦点时收到通知时才会调用
onNotification
函数。
If you need to handle a notification in the background before it is opened you will need to do so with native code. 如果您需要在打开通知之前在后台处理通知,则需要使用本机代码执行此操作。
iOS - set content_available
to true
on the OneSignal create notification REST API POST call, this will fire the - application:didReceiveRemoteNotification:fetchCompletionHandler: selector. iOS - 在OneSignal 创建通知 REST API POST调用上将
content_available
设置为true
,这将触发- application:didReceiveRemoteNotification:fetchCompletionHandler: selector。
Android - Setup a NotificationExtenderService
by following the OneSignal Background Data and Notification Overriding instructions. Android - 按照OneSignal 背景数据和通知覆盖说明设置
NotificationExtenderService
。
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 : 关于在android中实现
NotificationExtenderService
(不回答原始问题,但是@ryeballar提出的问题),如https://documentation.onesignal.com/docs/android-customizations#section-background-data-and-notification中所述- 覆盖 :
NotificationExtenderService
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 ): 但是,为了实现
NotificationExtenderService
您需要执行以下操作(如上面提到的那些信号文档中所述, 请注意那里有一个拼写错误,修复如下 ):
NotificationExtender.java
in node_modules\\react-native-onesignal\\android\\src\\main\\java\\com\\geektime\\rnonesignalandroid
, with the following contents: node_modules\\react-native-onesignal\\android\\src\\main\\java\\com\\geektime\\rnonesignalandroid
创建一个名为NotificationExtender.java
的文件,其中包含以下内容: . 。
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;
}
}
android\\app\\src\\main\\AndroidManifest.xml
: 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.