react-native-onesignal icon indicating copy to clipboard operation
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).

Open StanSarr opened this issue 2 years ago • 2 comments

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:

  1. Expo init MyAPP
  2. yarn add react-native-onesignal onesignal-expo-plugin
  3. setup onesignal-expo-plugin inside app.json (app.config.js)
  4. expo prebuild & setup service extension (https://documentation.onesignal.com/docs/service-extensions)
  5. Denied Notification request
  6. Use API to send notification

StanSarr avatar Jul 11 '22 15:07 StanSarr

@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 avatar Jul 12 '22 18:07 jkasten2

@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 Receiptwith 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.

StanSarr avatar Jul 20 '22 11:07 StanSarr