Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
1 task done
emreiszero opened this issue Dec 24, 2023 · 4 comments
Closed
1 task done

Comments

@emreiszero
Copy link

emreiszero commented Dec 24, 2023

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

  • I agree to follow this project's Code of Conduct
@jennantilla
Copy link
Contributor

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!

@rpinto18
Copy link

rpinto18 commented Jan 8, 2024

@jennantilla foregroundWillDisplay ios.

@fmp777
Copy link

fmp777 commented Aug 23, 2024

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!

@jennantilla
Copy link
Contributor

Hello there--apologies that this issue has gone stale.

Appreciate the above response to try adding the listeners right after initialization. Did that work for you?

Additionally, we have made many improvements to our SDK since this was reported that could resolve this issue. Please update to our latest version and if you still have any problems, feel free to create a new issue. Thanks!

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

No branches or pull requests

4 participants