phonegap-build / PushPlugin

This repository is deprecated head to phonegap/phonegap-push-plugin
https://github.com/phonegap/phonegap-plugin-push
MIT License
1.32k stars 996 forks source link

Backgound notification #403

Open cr1t opened 9 years ago

cr1t commented 9 years ago

Hi

I've got the latest plugin installed with phonegap v 3.5.0-0.21.18

When my application is notifications come threw and I output it to the console,

But when application is in the background no msg gets processed. I can see the msg coming threw in the logcat.

I've see somebody else had similar issue but was with older versions and they got it resolved

http://community.phonegap.com/nitobi/topics/_pushplugin_background_notifications_dont_seem_to_work

harmendejong commented 9 years ago

Hi,

We are having this issue too.

  1. When the app is open and running in the foreground, we do receive the push message.
  2. When the app is running in the background or the app is closed, no push messages are received. Neither in notification center nor on lockscreen.

Environment: Phonegap version 3.6.3, using Phonegap Build service PushPlugin version 2.4.0

marcbenito commented 9 years ago

Hello. I have the same problem :(

harmendejong commented 9 years ago

Does anybody have any suggestion about how to get to the cause of this issue?

Since we are receiving push messages when the app is running in the foreground, I suppose we can assume our settings and ID's are properly setup. So since we are stuck with this problem, any ideas on how to debug this issue would be really welcome.

cr1t commented 9 years ago

Well

I changed my payload to look like this

{"message":"Lorem ipsum dolor sit amet, consectetur adipisicing elit","notID":"0","messageID":"70efe25b-d8b1-492b-a0a7-32b411d6a925"},"from":"659651096010","collapse_key":"do_not_collapse","foreground":true,"event":"message"}

seems anything in the message it will display

harmendejong commented 9 years ago

@cr1t: Do you mean you got it working or fixed it with the payload you mentioned? Because this is totally different than the payload that Apple prescribes:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1

cr1t commented 9 years ago

Hey @harmendejong

I'm sending push notifications just to android and using GCM as the service I'm testing on a Android 4.0.4 device.

When I started my payload looked like this {"alert":"Hello World!", "badge":7,"sound":"sound.caf"}

with no notification working on the device when app was not in foreground.

After i changed to alert to message it started working.

I tested it by changing the message to something else and it stopped working.

I have no idea why? I can't find any documentation on the payload formats ect.

I'm yet to test on other android devices.

cr1t commented 9 years ago

PS I just found this

Example GCM Payload:

payload={"payload_gcm": { "alert":"Your Message", "sound":"default" "extra": { "u":"www.google.com" } } }

at

https://docs.push.io/API_&_cURL_Information/Platform_Specific_Payloads/GCM_(Google_Cloud_Messaging)

I'll try it and see what happens

playboi commented 9 years ago

I have this problem as well. After reading through the entire source of the plugin, I've found that the background service look specifically for the message and title attributes in your payload. After lots of reading and and some experiment, I've come up with the following solution:

  "collapse_key": "...",
  "time_to_live": "..",
  "delay_while_idle": "..",
  "data": {
    "title" : "...",
    "message": "...",
  ...
  },
  "registration_ids" : []

need to have the data field contain a title & message attribute that's great than a length of 0. The title field contains your notification title, and the message contains your message. Hope this helps.

Gionni commented 9 years ago

Hi guys, d'you recognize yourself in https://github.com/phonegap-build/PushPlugin/issues/423?

andreszs commented 9 years ago

@playboi Thanks, I wish I found this post 4 days ago when I started installing useless background-mode processes and all kind of time-wasting stuff. I wonder where you found them because GCM says nothing about them, and the plugin docs don't even mention the words "server side".

Now I only have to find out how to customize it to prevent the vibration and sound based on my app's preferences.

mypark commented 9 years ago

I lost a lot of time on this issue as well... perhaps we should update the readme to say that title and or message is required for Android?

This doesn't seem to be the same issue/requirement for the iOS side.

sushilbchq commented 9 years ago

use this key "message" in JSON While sending notification in json its has worked fine in background and foreground

example "{\"alert\":\"Student Update!\",\"badge\":7,\"event\":\"message\",\"message\":\"OK Done\",\"sound\":\"beep.wav\"}"