OneSignal / OneSignal-Cordova-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Other
250 stars 197 forks source link

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

Open emreiszero opened 8 months ago

emreiszero commented 8 months ago

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

jennantilla commented 8 months ago

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 commented 8 months ago

@jennantilla foregroundWillDisplay ios.

fmp777 commented 2 weeks ago

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!