-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Receive Notifications in Background #93
Comments
I've been debugging this with xcode. The else block is hit when the application is started as a result of the user tapping a notification when the app is not in the foreground (i.e. in the task switcher). In this case the plugin invokes the javascript 'notification' event callback with details of the push message when the init method is called. Out of interest, do you know if implementing the As a side note, after the app is force quit (double tap home, swipe up) and the device is locked, tapping a notification will bypass the |
I created a cordova plugin some time ago when using UrbanAirship to receive notifications in the background. Implementing the The important thing is that one must allow Javascript to signal the end of the For example:
|
+1 for this feature |
@christocracy please feel free to send a PR with this functionality. |
When PhoneGap fixes their plugin and stops including static jar files (eg android-support-v4.jar), breaking other peoples' plugins, I'll consider contributing a PR. |
Are there any other good plugins for push I can use that does not break other plugins? |
@christocracy I'm in a bit a bind right now as PhoneGap build which I need to support does not support gradle yet. Once it does I already have a commit to make the change. I'd love for you to participate in this plugin. So if you can contribute code that would be great. @cmartin81 I'd say this one is your best bet and I will resolve this compilation issue as quickly as I can. |
@macdonst When might PGB support gradle? It won't be soon enough, I'm afraid. I'm so tired of providing support for PGB users of my products. Until PGB supports gradle, I strongly recommend my customers against using PhoneGap and point them towards more advanced build-services which do support grade, such as CloudFive |
@christocracy what exactly do you mean by "receive notifications while in the background"? Because on this issue I notice I can receive notifications only when the app is in foreground. When the app is closed or not in the foreground, nothing happens at all. I don't know if this is what this issue is about but for me this is not an enhancement but a bug as it makes the plugin barely unusable :'( |
For ios in particular, an app can receive a push notification while the app is in the background. iOS can awaken the app in the background and provide exactly 30s of background running-time. But only if the push-plugin implements the application:didReceiveRemoteNotification:fetchCompletionHandler: method variant This plugin does not implement this variant thus an iOS app cannot be awakened in the background due to a push request. An example usage of this feature could be a server which desires to know the geolocation of a device or devices. The server could send a silent "where are you?" push-request with a JSON-body only (e.g.: This is how Apple's "Find Friends" app works. |
Ok so that seems nice for background sync but it may not be related to my problem :) thanks |
+1 |
Does this mean that right now this plugin can not handle push notifications when app is in background? |
Without a doubt, this plugin can only receive a Push notification while On Saturday, September 5, 2015, Bernd Artmüller [email protected]
Snet form Gmail Mobile |
Hmm, is there a simple way to fix this myself? I tried to enable "Remote notifications" but that did not work. |
No simple way. It needs an obj-c method implemented including some careful handling of the completionHandler callback, as I clearly documented above, including an example usage from one of my plugins. |
Ok, but the deprecated plugin https://github.com/phonegap-build/PushPlugin also does not implement the "application:didReceiveRemoteNotification:fetchCompletionHandler:" method, nevertheless background notifications are working. |
You're not understanding. Speaking of iOS, in particular, With your app running in background, you However, your JavaScript callback is not being executed. What if the push The JavaScript callback cannot be executed in the background with this On Saturday, September 5, 2015, Bernd Artmüller [email protected]
Snet form Gmail Mobile |
Oh sorry, then we are talking about different things. I'm sending push notifications to my unlocked iOS device (app is in background) and would like them to display with a banner. iOS receives the notification but does not display it with a banner (like WhatsApp). |
If you want to execute a js callback in background due to push, this plugin On Saturday, September 5, 2015, Bernd Artmüller [email protected]
Snet form Gmail Mobile |
@christocracy I'm trying to understand a little better to know if issue #109 is a duplicate or not I'm thinking of different usecases: Receiving notifications in foreground:No problem here. Receiving notification in background and notification to the user:When the user clicks on the notification, the app should open and the notification callback be triggered. Receiving notification in background, and executing callback while still in backgroundAs far as I understand this is your usecase no? I understand that you want to be able to run js code for 30 seconds inside the Cordova app, without even putting this app in foreground. I think #109 is more about the 2nd case, as the user mention he "opens the app" while you never open the app in your usecase |
My concern is use-case #3. On Monday, September 7, 2015, Sébastien Lorber [email protected]
Snet form Gmail Mobile |
+1 |
2 similar comments
+1 |
+1 |
* 'master' of github.com:phonegap/phonegap-plugin-push: Version 1.4.2 Issue phonegap#299: 1.4.x not showing notification on Android Version 1.4.1 Issue phonegap#295: data.registrationId is empty string "" on register event callback Issue phonegap#291: Reregister on Android [typo] fixing .finish() example Update CHANGELOG Version 1.4.0 Issue phonegap#93: Receive Notifications in Background
@macdonst THANKS for the work on this feature. I updated the plugin through cordova rm plugin and cordova add plugin, but from what I see (im new to cordova dev), the version i get is not the latest from git ? is there a normal delay between versions here and the ones we get from cordova add plugin ? thanks in advance PS: i figured out I should i use : cordova plugin add https://github.com/phonegap/phonegap-plugin-push ? |
I am curious about a question of GCM payload. For example, if I need to show notification in the shade when app is in background, this plugin requires the payload to be like: {
"to" : registrationId,
"data" :
{
"title" : "Portugal vs. Denmark",
"message" : "Data: please check score",
"myOwnData": "blablabla"
}
} However, per "Hybrid messages with both notification and data payload" section of Google's official website: https://developers.google.com/cloud-messaging/concept-options It mentions "notification" and "data" fields. And "title", "message" should be put in the "notification" so that Android will show them in the shade for background app. My speculation is that this plugin modifies the default Android behavior so that "title", "message" can be put in "data" field. Is this correct? |
@rastermax if you do an add directly from the git url you'll get the current development version. It may or may not be stable. @gongfan99 the latest version of the plugin should work with data/notification in the same payload. |
Hi, |
background notification not working on android |
I do receive the notification however when it opens the application the push notification wont work instead: |
@barocsi then you need to look at where you access 'id' in your |
Thanks @macdonst the problem was on my side. |
has anyone been able to receive notifications in background on android? i cant seem to catch it at all and i always get an error when i do this as well
All not working and all give me the same error, pushPlugin.on('notification') is not a function. How do i call the phonegap-plugin-push from my deviceready event? |
@boyfunky just try the hello world example first maybe? https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/EXAMPLES.md |
@boyfunky make sure you run "cordova plugin add phonegap-plugin-push" before you run "cordova build" |
@gongfan99 yes i have already done that. @deceadmin how did you solve ur issue. I am having the same exact issue. |
hi, maybe that can help. var notifMessage = new gcm.Message({ var regTokens = [obj.android_push_id]; //destination user push id var sender = new gcm.Sender(GOOGLE_CLOUD_MESSAGING_KEY); //your GOOGLE sender.send(notifMessage, {registrationTokens:regTokens}, Hope it can help. On Tue, Mar 1, 2016 at 10:31 PM, Kingsley Simon [email protected]
|
@boyfunky, i could not solve it |
For Android it so doesn't work when app is in background. Is there any alternate plugin. which do not have such issues? |
I finally solved my background android issue! I would receive fine when app in the foreground, and would happily receive the tray notification when in the background, but my push.on('notification', function(data) {} would not fire at all in the background .... which is what I really wanted as I want to activate the GPS without the user having to click the tray notification. I knew I had to set content_available = 1 ... BUUUUT it is content-available and NOT content_available!! Silly mistake, but I think the "content_available": true, example in the docs threw me! Hope that helps someone! |
Hello All |
No event-handler called with background app on iOS (it works on android), using GCM/FCM.
Is documentation here updated? The "aps" object seem totally ignored on iOS ( aps.alert present or missing has no effects) |
Does your iOS app have the background "notification" entitlement in the
.plist?
--
Snet form Gmail Mobile
|
It's a ionic app, and on xcode I've enabled the remote notifications in Background Modes. |
@bfx This may be a bit dated but I'm working through the same documentation now on version 2.0.x version of the code. I believe the docs you are referring to above referencing the payload are in fact the docs for the APNS version of the API. If I understand it properly, node-gcm sends to google who turns around and sends to APNS for you. https://firebase.google.com/docs/cloud-messaging/http-server-ref indicates you should likely be sending something like:
Note the Hope that helps, but as with most things, YMMV. Cheerio. |
@coderroggie btw content-available should be "content_available": true, |
This thread has been automatically locked. |
This plugin is unable to receive notifications while in the background since it doesn't implement application:didReceiveRemoteNotification:fetchCompletionHandler:
Discussion
Clearly this logic in
didReceiveRemoteNotification
is useless, since that method is only called in the foreground.The text was updated successfully, but these errors were encountered: