Search code examples
cordovapush-notificationphonegap-pluginsphonegap-pushplugin

How to handle push notifications with Cordova as they arrive and the app is closed


Can I somehow detect push notification arrival and handle it using cordova when notification arrives and app is closed at that time? I am using cordova com.clone.phonegap.plugins.pushplugin but when notification arrives and app is closed then the event listeners registered by me using plugin javascript code are not 'alive' and I can't detect the arrival. Is it possible to achieve that in some other way using cordova?


Solution

  • If you are asking for iOS, then no. Your app cannot handle User notifications while in the background. If the user taps the notification banner, your app will open and you will get a callback with the notification payload which can be forwarded to JavaScript.

    If you would like to process silent background notifications, that has to be done in native because JavaScript execution is suspended in the background AFAIK. You could implement a queue which just stores a background notification and then dispatches it to JavaScript when app returns to active state.