Hi,
We have included a service to send notifications(OneSignal.postNotification), in ComponentDidMount, in index.ios.js file. However, we are successfully receiving in-app notifications but unable to receive notifications when app is closed or running in background.
We have checked the system setting for our app and 'Background check' is ON.
RN Version: "0.48.4",
One Signal : "3.0.5",
Devices Checked on : Android and IOs - both not working
Any help will be appreciated.
Hi, its related to #209, #264, and im having the same problem.
you should set contentAvailable to true in OneSignal when sending the notification
I have made an application using the react native and onesignal (thanks for the effort that put in to build this wonderful library).
I am able to receive the notifications from onesignal, but if app is not running and push notification is received then clicking on the push notification doesn't navigate to the desired screen. Please suggest me a solution for this problem. How this can be solved?
I am using the route-flux for routing in my app.
This is not an issue when app is running and notification is received.
@HananeAlSamrout If I send the contentAvailable parameter as true, the notification is not triggered when the application is closed. Could you send me a sample setup?
Just a heads up that I've posted a pretty lengthy comment at https://github.com/geektimecoil/react-native-onesignal/issues/332#issuecomment-341326624 discussing this problem.
@HananeAlSamrout but that is just relevant on iOS right? I am not receiving notifications on Android when the app is closed.
I am also not receiving notification in some device running 6.0 and 7.0 when app is closed. I am using library
compile 'com.onesignal:OneSignal:[3.6.4,4.0.0]'
If some one solved this problem, please help.
Thanks
@ccoeder make sure also to set onesignal in xcode AppDelegate as follows:
self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
appId:@"appId"
settings:@{kOSSettingsKeyInFocusDisplayOption : @(OSNotificationDisplayTypeNotification), kOSSettingsKeyAutoPrompt : @YES}
];
and
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
[RCTOneSignal didReceiveRemoteNotification:notification];
}
@natterstefan true, only for ios devices, i am also facing this issue on android i didn't find a solution yet
It's now fixed on the latest release.
@avishayil Sounds great, but only for iOS right?
Nope, also android.
Just for the record, it looks like it's working fine on Android.
@avishayil @natterstefan I'm looking a way to get notification when app is closed.I get just when app is open or in ios. but not in android(when closed, when open I get). do you have any example project or way to explain me?
@adirzoari how have you implemented it in your app, the way it is explained here: https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup#section-usage?
@natterstefan yes, exactly like in the tutorial
in addition i added notificationExtenderService as described in this tutorial https://documentation.onesignal.com/docs/android-customizations#section-background-data-and-notification-overriding
Reading the documentation, if the app is closed there's no way to wake it up:
content_available:
Sending true wakes your app from background to run custom native code (Apple interprets this as content-available=1). Note: Not applicable if the app is in the "force-quit" state (i.e app was swiped away). Omit the contents field to prevent displaying a visible notification.
"react-native-onesignal": "3.2.4"
@adirzoari @avishayil @natterstefan
@avishayil @natterstefan I'm looking a way to get notification when app is closed.I get just when app is open or in ios. but not in android(when closed, when open I get). do you have any example project or way to explain me?
Do you get notifications on android when the app is closed (swiped away, or even not started after boot)?
Did you succeed to do it without Android Notification Extender Service?
still not working here (Android), only get notification when the app is open or minimized, no notification is received when closed
I would like to add that I'm currently having the same issue, though mine probably differs in that I'm first sending a notification to and Android 7 device through the dashboard. Currently I got a notification only when I have the app open in focus (ionic 3 app), however I found that when it isn't in focus then the device vibrates for half a second only. I'll post this as a separate issue though so I can detail the settings I used on the dashboard.
@Mixpeal @iranicus @rahamin1
Handle notification when android app is close:
service:
import com.onesignal.NotificationExtenderService;
import com.onesignal.OSNotificationReceivedResult;
....
public class NotificationExtender extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult notification) {
// TODO you can do everything what do you want with `notification`
return false;
}
}
don't forget to register it in Manifest:
<service
android:name="your.packager-name.notificationManager.NotificationExtender"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
if you put log into onNotificationProcessing and open and close app service will be listening for all notification which comes And all what you need is setup react-native-onesignal
And i need some void for IOS any ideas?
more info https://stackoverflow.com/questions/54286742/how-to-get-active-notification-list-at-app-start
@NetPumi2 where am i going to place the code to enable this function?
Is it this file?

@dotmarn Yes I think this is the correct directive
I think this https://documentation.onesignal.com/docs/android-customizations#section-background-data-and-notification-overriding can help this issue 馃憤
But it didnt work
@Mixpeal @iranicus @rahamin1
Handle notification when android app is close:
service:import com.onesignal.NotificationExtenderService; import com.onesignal.OSNotificationReceivedResult; .... public class NotificationExtender extends NotificationExtenderService { @Override protected boolean onNotificationProcessing(OSNotificationReceivedResult notification) { // TODO you can do everything what do you want with `notification` return false; } }don't forget to register it in Manifest:
<service android:name="your.packager-name.notificationManager.NotificationExtender" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false"> <intent-filter> <action android:name="com.onesignal.NotificationExtender" /> </intent-filter> </service>if you put log into
onNotificationProcessingand open and close app service will be listening for all notification which comes And all what you need is setupreact-native-onesignalAnd i need some void for IOS any ideas?
more info https://stackoverflow.com/questions/54286742/how-to-get-active-notification-list-at-app-start
My friend, These steps dont working on
"react": "16.8.3",
"react-native": "0.59.9",
"react-native-onesignal": "^3.5.0"
Just see my System.out.println on my logs, but even dont see any notification on my phone or device emulator ;(
Any ideas?
Thanks in advanced.
Most helpful comment
@ccoeder make sure also to set onesignal in xcode AppDelegate as follows:
and