Skip to content

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

@009topersky

Description

@009topersky

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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions