New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google cloud messaging GCM - Push Notification not being sent (Server Side) #110

Closed
dummyltpl opened this Issue Sep 7, 2015 · 12 comments

Comments

Projects
None yet
4 participants
@dummyltpl

Hi,
I am able to get the device id and save it to my database, and when something happens, I try to send the push notification and get the response
"{"multicast_id":5913087252880472009,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1441610705462116%d477807af9fd7ecd"}]}"
but it does not get delivered to the phone.
Here is what I do in my PHP:

'here is a message. message', 'title' => 'This is a title. title', 'subtitle' => 'This is a subtitle. subtitle', 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 'vibrate' => 1, 'sound' => 1, 'largeIcon' => 'large_icon', 'smallIcon' => 'small_icon' ); $fields = array ( 'registration_ids' => $registrationIds, 'data' => $msg ); $headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch ); curl_close( $ch ); echo $result; ?>

Please help me to resolve this issue.

@slorber

This comment has been minimized.

Show comment
Hide comment
@slorber

slorber Sep 7, 2015

Contributor

This may be related: #101

@dummyltpl try to put your app in foreground and try again.

Also use the command "adb logcat" to see if your mobile receive the push (it may receive it but not displaying it)

Contributor

slorber commented Sep 7, 2015

This may be related: #101

@dummyltpl try to put your app in foreground and try again.

Also use the command "adb logcat" to see if your mobile receive the push (it may receive it but not displaying it)

@dummyltpl

This comment has been minimized.

Show comment
Hide comment
@dummyltpl

dummyltpl Sep 8, 2015

trying to put app in foreground and its not working.Unable to figure out the issues.
Please suggest to resolve this issue.

trying to put app in foreground and its not working.Unable to figure out the issues.
Please suggest to resolve this issue.

@slorber

This comment has been minimized.

Show comment
Hide comment
@slorber

slorber Sep 8, 2015

Contributor

@dummyltpl when you send the push, give the logs of adb logcat command. You should see your mobile is receiving the push (but sometimes it does not display it)

Without the logs you don't help to resolve the issue.

Also give the code in your app where you listen for notifications.

Also, try using curl instead of your php code and don't forget to put a title/body:

curl --header "Authorization: key=apiKey" \
     --header Content-Type:"application/json" \
     https://gcm-http.googleapis.com/gcm/send \
     -d '{
    "to": "registrationId",
    "notification": {
        "title": "title",
        "body":"body",
     }
}'

Also test both in background/foreground (and give logcat logs for both)

You can also give a try to this fork which solved an issue I had: <plugin name="phonegap-plugin-push" spec="https://github.com/slorber/phonegap-plugin-push.git#master" />

Contributor

slorber commented Sep 8, 2015

@dummyltpl when you send the push, give the logs of adb logcat command. You should see your mobile is receiving the push (but sometimes it does not display it)

Without the logs you don't help to resolve the issue.

Also give the code in your app where you listen for notifications.

Also, try using curl instead of your php code and don't forget to put a title/body:

curl --header "Authorization: key=apiKey" \
     --header Content-Type:"application/json" \
     https://gcm-http.googleapis.com/gcm/send \
     -d '{
    "to": "registrationId",
    "notification": {
        "title": "title",
        "body":"body",
     }
}'

Also test both in background/foreground (and give logcat logs for both)

You can also give a try to this fork which solved an issue I had: <plugin name="phonegap-plugin-push" spec="https://github.com/slorber/phonegap-plugin-push.git#master" />

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Sep 8, 2015

Member

@slorber thank you for responding to issues and contributing code, it is greatly appreciated.

Also, I just pushed 1.2.3 to npm so you don't need to use the url to the master branch.

Member

macdonst commented Sep 8, 2015

@slorber thank you for responding to issues and contributing code, it is greatly appreciated.

Also, I just pushed 1.2.3 to npm so you don't need to use the url to the master branch.

@slorber

This comment has been minimized.

Show comment
Hide comment
@slorber

slorber Sep 9, 2015

Contributor

np ok thanks i'll use this version instead :)

Contributor

slorber commented Sep 9, 2015

np ok thanks i'll use this version instead :)

@roysG

This comment has been minimized.

Show comment
Hide comment
@roysG

roysG Sep 17, 2015

same problem for me, i get registered id but i do not get any push.

roysG commented Sep 17, 2015

same problem for me, i get registered id but i do not get any push.

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Sep 17, 2015

Member

@roysG how are you sending the push? Need some details if I can debug.

Member

macdonst commented Sep 17, 2015

@roysG how are you sending the push? Need some details if I can debug.

@roysG

This comment has been minimized.

Show comment
Hide comment
@roysG

roysG Sep 17, 2015

i am sending the push through node js, this code worked great with previous(deprecated) version of the push plugin.

Code below:

var message = new gcm.Message();

//API Server Key
var sender = new gcm.Sender('xxxxxxxxxxxxxx');
var registrationIds = [];

// Value the payload data to send...
message.addData('message',msgs);
message.addData('title',' PickTags');
message.addData('msgcnt',counterMsgs); // Shows up in the notification in the status bar
message.addData('soundname','beep3'); //Sound to play upon notification receipt - put in the www folder in app
message.addData('sound',false); //Sound to play upon notification receipt - put in the www folder in app

    if(imgDeal && (imgDeal.indexOf('.png') || imgDeal.indexOf('.jpg')))
        message.addData('bigPicture',imgDeal); //Sound to play upon notification receipt - put in the www folder in app

//message.collapseKey = 'demo';
//message.delayWhileIdle = true; //Default is false
message.timeToLive = 3000;// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.

        registrationIds.push(device);
    sender.send(message, registrationIds, 4, function (result) {
        console.log(result);
    });

roysG commented Sep 17, 2015

i am sending the push through node js, this code worked great with previous(deprecated) version of the push plugin.

Code below:

var message = new gcm.Message();

//API Server Key
var sender = new gcm.Sender('xxxxxxxxxxxxxx');
var registrationIds = [];

// Value the payload data to send...
message.addData('message',msgs);
message.addData('title',' PickTags');
message.addData('msgcnt',counterMsgs); // Shows up in the notification in the status bar
message.addData('soundname','beep3'); //Sound to play upon notification receipt - put in the www folder in app
message.addData('sound',false); //Sound to play upon notification receipt - put in the www folder in app

    if(imgDeal && (imgDeal.indexOf('.png') || imgDeal.indexOf('.jpg')))
        message.addData('bigPicture',imgDeal); //Sound to play upon notification receipt - put in the www folder in app

//message.collapseKey = 'demo';
//message.delayWhileIdle = true; //Default is false
message.timeToLive = 3000;// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.

        registrationIds.push(device);
    sender.send(message, registrationIds, 4, function (result) {
        console.log(result);
    });
@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Sep 17, 2015

Member

@roysG I see no reason why that wouldn't work. My test gcm.js file is very similar. Are you remembering to updated your registration ID you get from the registration event in the registrationIds array?

Other than that run adb logcat | grep PushPlugin to capture what the push plugin sees and send a push to your device. That might help me debug.

Member

macdonst commented Sep 17, 2015

@roysG I see no reason why that wouldn't work. My test gcm.js file is very similar. Are you remembering to updated your registration ID you get from the registration event in the registrationIds array?

Other than that run adb logcat | grep PushPlugin to capture what the push plugin sees and send a push to your device. That might help me debug.

@roysG

This comment has been minimized.

Show comment
Hide comment
@roysG

roysG Sep 17, 2015

i did the test with adb logcat | grep PushPlugin, but i get nothing, there is no any message.
:(

can you send me your gcm.js test ?

and write my your steps, i do not understand why is happen, i follow the steps for the installation.

roysG commented Sep 17, 2015

i did the test with adb logcat | grep PushPlugin, but i get nothing, there is no any message.
:(

can you send me your gcm.js test ?

and write my your steps, i do not understand why is happen, i follow the steps for the installation.

@roysG

This comment has been minimized.

Show comment
Hide comment
@roysG

roysG Sep 18, 2015

@macdonst, many thanks,
I found my problem, i just miss the correct sender ID !!

roysG commented Sep 18, 2015

@macdonst, many thanks,
I found my problem, i just miss the correct sender ID !!

@macdonst macdonst closed this Sep 18, 2015

@lock

This comment has been minimized.

Show comment
Hide comment
@lock

lock bot Jun 5, 2018

This thread has been automatically locked.

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.