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.
Their documentation stated that:
When any notification is opened or received the callback
onNotification
is called passing an object with the notification data.
But onNotification
clearly does not work.
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.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
totrue
on the OneSignal create notification REST API POST call, this will fire the - application:didReceiveRemoteNotification:fetchCompletionHandler: selector.Android - Setup a
NotificationExtenderService
by following the OneSignal Background Data and Notification Overriding instructions.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
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):NotificationExtender.java
innode_modules\react-native-onesignal\android\src\main\java\com\geektime\rnonesignalandroid
, with the following contents:.
android\app\src\main\AndroidManifest.xml
:.