fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
624 stars 999 forks source link

When app is killed, data Notification does not result in a FCMPlugin.onNotification() callback. #295

Open sasrinidhi opened 7 years ago

sasrinidhi commented 7 years ago

I'm sending a data notification to wake up the app and download data. I get a callback in FCMPlugin.onNotification() while the app is in foreground or background but not when the app is killed.

Even though the app 'wakes up' upon receiving a notification while the app is killed, I don't get a callback in the plugin. I see this error in the Android Console.

View not ready. SAVED NOTIFICATION: javascript:FCMPlugin.onNotificationReceived({"NOTIF_TITLE":"","priority":"high","wasTapped":false,"NOTIF_BODY":"","NotificationTypeId":"10"})

This error is originating from FCMPlugin:sendPushPayload(). There is a specific check in the code which prevents from making the callback.

if(notificationCallBackReady && gWebView != null){ Log.d(TAG, "\tSent PUSH to view: " + callBack); gWebView.sendJavascript(callBack); }else { Log.d(TAG, "\tView not ready. SAVED NOTIFICATION: " + callBack); lastPush = payload;

I want to do a background data refresh regardless of whether the app is running. How do I implement this?

maxper75 commented 7 years ago

Hi, I tried the same and for what I understood with this plugin there's no way. The actual way, for android (still didn't have a clue to test it on iOS) is to create a service that runs in background. The main problem is that if you have such a service via so you integrate it in cordova app? If it's my first situation, so even I don't really know how to solve the problem...

pierrybos commented 7 years ago

The Firebase send a message to android and this will be delivered on status bar. Ok. If (and only if) user tap on notification the app will wake up and "FCMPlugin.onNotification" will be called.

vahidreza commented 5 years ago

@pierrybos this exact thing you said does not work for me for plugin 2.1.2 version. it only works when app is in the foreground! this is a very simple functionality i guess. for other plugin like onesignal I see an expected behavior. launching app and calling callback if app is killed before, is in the background or is in the foreground. what's the solution?

telran commented 5 years ago

I find a solution, when I use cordova-plugin-fcm and install cordova-plugin-push too, the background push notifications (on notification click) triggered on ios now.