OneSignal-Cordova-SDK
OneSignal-Cordova-SDK copied to clipboard
[question]: When a push notification comes while the app is closed, no event is fired
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
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 foregroundWillDisplay ios.
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!