OneSignal-Cordova-SDK icon indicating copy to clipboard operation
OneSignal-Cordova-SDK copied to clipboard

[question]: When a push notification comes while the app is closed, no event is fired ​

Open emreiszero opened this issue 1 year ago • 3 comments

How can we help?

import { boot } from 'quasar/wrappers' import OneSignal from 'onesignal-cordova-plugin'; import { userStore } from 'stores/userstore'; export default boot(async ({router}) => { const store = userStore() const {SetQuestion,SetQuestion_succcess,SetPushNo,SetTrackingSuccess,SetWorkingSuccess,SetPushCompanyNo,SetActiveWorking_Security} = store; const OneSignalInit = async () => { OneSignal.initialize(oneSignalAppId); OneSignal.Location.isShared(true) OneSignal.User.setLanguage("tr") OneSignal.Location.requestPermission()

  OneSignal.Location.setShared(true)
  await OneSignal.Notifications.requestPermission(true).then((accepted) => {

    }).catch((error) => {

    });

}; let OneSignalPushView = async () => { let myClickListener = async function (event) { console.log(event) if (event.notification.additionalData && event.notification.additionalData.is_field_success === true) { SetQuestion(event.notification.body); SetQuestion_succcess(true) SetTrackingSuccess(event.notification.additionalData.success) SetWorkingSuccess(event.notification.additionalData.working) SetPushNo(event.notification.notificationId) SetPushCompanyNo(event.notification.additionalData.company_no) router.push('/PN_View') } else if (event.notification.additionalData && event.notification.additionalData.is_register_success === true) { SetActiveWorking_Security(true) router.push('/index') } }; OneSignal.Notifications.addEventListener("click", myClickListener); OneSignal.Notifications.addEventListener("foregroundWillDisplay", myClickListener); };

document.addEventListener('deviceready', OneSignalInit ,false); document.addEventListener('deviceready', OneSignalPushView ,false); document.addEventListener('pause', OneSignalPushView ,false); document.addEventListener('resume', OneSignalPushView ,false);

});

Hello, first of all, I apologize for my English, this is my project that I wrote with the quasar framework. I made such push settings in the boot files. The event is fired when the app is in the foreground, but it does not happen when the application is closed. What am I doing wrong here? ​

Code of Conduct

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

emreiszero avatar Dec 24 '23 15:12 emreiszero

Hello @emreiszero thanks for reaching out! Just to clarify, which event are you referring to? Is it the click event or the foregroundWillDisplay event? Thank you for the additional details!

jennantilla avatar Dec 28 '23 22:12 jennantilla

@jennantilla foregroundWillDisplay ios.

rpinto18 avatar Jan 08 '24 14:01 rpinto18

We ran into this too, but only on Android and with the click event. Worked fine if app is in foreground (foregroundWillDisplay), but if app is closed, and notification clicked, the 'click' event handler was not fired on android, but worked great on IOS.

The solution was to add the eventListeners as early as possible in the app initialization process.

Maybe that info will help a future searcher!

fmp777 avatar Aug 23 '24 17:08 fmp777