OneSignal / OneSignal-Cordova-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Other
251 stars 198 forks source link

[question]: How to handle the Silent Notification in release version 3.x.x? is there any guides or sample codes. #835

Open 009topersky opened 1 year ago

009topersky commented 1 year ago

How can we help?

Good day everyone!

We've been using OneSignal for quite some time and implemented it for several projects. We migrated the version of OneSignal from 2.x.x into 3.x.x and it seems fine.

The problem is that we have some implementation in silent notification wherein there are no headings and contents.

To simulate the issue.

STEP 1: We sent the data from the OneSignal REST API

POST: https://onesignal.com/api/v1/notifications

HEADERS: Authorization: Bearer <ONESIGNAL_REST_API_KEY>

PAYLOAD:

{   
    "app_id": "ONESIGNAL_APP_ID",
     "huawei_msg_type": "data",
     "data": {"notificationContext": "timelog-break-out"},
     "content_available": true,
     "include_external_user_ids": ["Supervisor-external-id1"],
     "isAppInFocus": true
}

STEP 2: In ionic 3 framework under the upon initialization of app based on the documentation https://documentation.onesignal.com/docs/ionic-sdk-setup.

import OneSignal from 'onesignal-cordova-plugin';
...
constructor() {
    OneSignal.setAppId(environment.ONESIGNAL_APPID);

    // Actions for opening the push notification
    OneSignal.setNotificationOpenedHandler(function(notificationOpenedEvent) {
        console.log('setNotificationOpenedHandler:::', notificationOpenedEvent);
        const notif = notificationOpenedEvent.notification;
        notificationOpenedCallback(notif);
      });

    // Actions when receiving the notification in forebackground
     OneSignal.setNotificationWillShowInForegroundHandler(function(notificationReceivedEvent) {
        console.log('setNotificationWillShowInForegroundHandler:::', notificationReceivedEvent);
        const notif: any = notificationReceivedEvent.getNotification();

        notificationShowCallback(notif);
        notificationReceivedEvent.complete(notif);
      });
}
...

My goal is that the application should receive silent notifications even if the app is idle or in the background.

We already checked this documentations: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-service and https://documentation.onesignal.com/docs/data-notifications

but there are no specific docs that pertain to the implementation of backgrounds/silent notifications.

Sample codes and implementations could help us solve the issue.

Thanks. Have a nice day!

Code of Conduct

matheusssoares commented 1 year ago

I have the same problem, any examples to help?

anatoly-spb commented 1 year ago

I have proposed the following PR https://github.com/OneSignal/OneSignal-Cordova-SDK/pull/876 to support data/background messages on Android

anatoly-spb commented 1 year ago

It seems to me we have to migrate to Firebase SDK from OneSignal SDK, because there are no one to maintain this project.