react-native-onesignal
react-native-onesignal copied to clipboard
Silent (Data) notifications are not received on IOS and Android when the notification request is denied (disable on Android).
Hi guys, I'm running into an issue with the data notification.
Description:
Silent notifications are not received on IOS and Android when the notification request is denied (disabled on Android).
When I check my log, I can see that when the permission is authorized, the user receives both a push notification and a silent (data) notification, but when I delete my app and reinstall it. Suppose the notification request is denied or not asked (not prompted). Neither the push notification nor silent (data) notification is received.
When the permission request is accepted: didReceiveRemoteNotification
is called so does the NotificationServiceExtensionModule
// Explicitly define remote notification delegates to ensure compatibility with some third-party libraries
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//access NotificationServiceExtensionModule emitNotificationEvent method
NSLog(@"--------received------------");
[NotificationServiceExtensionModule.sharedInstance emitNotificationEvent:userInfo ];
return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
But when the Notification is denied or disabled (Android): Nothing is called neither didReceiveRemoteNotification
nor emitNotificationEvent:userInfo
from NotificationServiceExtensionModule
One signal API SIDE: I'm testing the push notifications and data notifications via one signal API. The request looks like this:
HTTP Request (OSRequestPostNotification) with URL: https://api.onesignal.com/notifications, with parameters: {
"data" : {
"params1" : true,
"params2" : true
},
"content_available" : true,
"mutable_content" : true,
"include_player_ids" : [
"xxxxxxxx-f114-xxxx-xxxx-bcd00744a44c"
],
"app_id" : "7ca99463-xxxx-xxx-xxxx-ea1657499790"
}
- The response when the request is accepted:
{ "id": "xxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx", "recipients": 1, "external_id": null }
- The response when the request is denied:
{
"id": "",
"recipients": 0,
"errors": [
"All included players are not subscribed"
]
}
or
{
"id": "xxxxxxx-xxxx-xxx-xxxx-xxxxxxxxxxx",
"recipients": 17,
"external_id": null,
"errors": {
"invalid_external_user_ids": [
"xxxxxxxxxxxxxxxxxxxxxxxxx"
]
}
}
Environment
- Expo SDK 45
- "onesignal-expo-plugin": "^1.0.2",
- "react-native-onesignal": "^4.3.10", ** No other notification is installed**
Steps to Reproduce Issue:
- Expo init MyAPP
-
yarn add react-native-onesignal onesignal-expo-plugin
- setup
onesignal-expo-plugin
insideapp.json (app.config.js)
- expo prebuild & setup service extension (https://documentation.onesignal.com/docs/service-extensions)
- Denied Notification request
- Use API to send notification
@StanSarr Thanks for your question. This is possible on Android if you write native code (Java / Kotlin) to handle the background data. You call OneSignal.unsubscribeWhenNotificationsAreDisabled(false)
to keep the player subscribed when notifications are disabled.
There is no setting to keep the device subscribed in the case of iOS. Apple has more restrictions on background pushes, they do not fire when the user swipes away the app being the biggest one.
Just for reference, it looks like you followed the guide here: https://documentation.onesignal.com/docs/rn-android-native-module-setup-for-notification-service-extension
Could you let us know what your use cases are for silent background notifications?
@jkasten2
Thanks for your answer.
Everything is working great when notifications are enabled on both IOS and Android.
I'll try this one OneSignal.unsubscribeWhenNotificationsAreDisabled(false)
on Android.
I'm using background notifications to update user information to improve user experience.
In my case, I have a Receipt
with different status. I want to update the receipt information and the data without harassing the users with regular notifications or loading when the app is opening.