Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
umeshpatra opened this issue Sep 17, 2024 · 0 comments

Comments

@umeshpatra
Copy link

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant