Skip to content

how to listen to receive notification event or click notification event #60

Open
@umeshpatra

Description

@umeshpatra

Description:
I'm trying to use onesignal web push notifications. from dotnet api, i send the notification successfully. in front-side, i get the notification and it gets displayed inside asp.net web pages. All is good, but what I need now is when I get the notification on the front-side, i have to do consume the entire event data and do further processing and UI refresh etc.
Which leads me to the situation where I need to know when notification gets received on front-side. It failed with TypeError: OneSignal.on is not a function with bellow code
<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
window.OneSignalDeferred = window.OneSignalDeferred || [];
OneSignalDeferred.push(async function (OneSignal) {
await OneSignal.init({
appId: "04680373-b77a-40be-b9df-477de5b5f902", notifyButton: {
enable: true
},
serviceWorkerParam: { scope: "/js/" },
serviceWorkerPath: "/js/OneSignalSDKWorker.js",
});

    });

    OneSignalDeferred.push(async function (OneSignal) {            
        OneSignal.on('notificationDisplay', function (event) {
            console.log('OneSignal notification displayed:', event);
        });
    });
    OneSignalDeferred.push(async function (OneSignal) {
        OneSignal.on('notificationDismiss', function (event) {
            console.log('OneSignal notification dismissed:', event);
        });
    });
  
</script>

I have already gone thru those pages. any guidance or help is appreciated.

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