fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
623 stars 997 forks source link

Please share code of test server #169

Open solucionesmipc opened 7 years ago

solucionesmipc commented 7 years ago

Hi;

i can receive notifications when using your test server "https://cordova-plugin-fcm.appspot.com/"

but when try my own php server, i receive message in android but not in IOS.

please share that PHP code. (i guess it is PHP)

Thanks a lot : )

it is my php code. working in android.

`<?php // API access key from Google API's Console define( 'API_ACCESS_KEY', 'AIzaSyA6SJ2Tw29mM09JUW1DKCdfddfdRBoXBo' ); // set only for one for safety $registrationId = $_GET['id']; $texto = $_GET['texto']; // prep the bundle $msg = array ( 'title' => 'Atenciòn.', 'body' => $texto, 'priority' => 'high', 'icon' => 'myicon', 'sound' => 'default'

); $fields = array ( 'to' => $registrationId, 'notification' => $msg );

$headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' );

$ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/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, true ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch ); curl_close( $ch ); echo $result; ?>`

aeremin commented 7 years ago

Example of python server: https://github.com/sth-larp/deus-mobile/blob/master/tools/send_to_fcm.py By the way, never publish your API access key - it will allow anyone spam users of your application with push notifications.

solucionesmipc commented 7 years ago

hi, thanks for your help

i tried code you sent, it works in android but not in ios.

i assume ios app is ok, i receive messages from firebase console and from plugin author's test server without any issue.

thanks.

aeremin commented 7 years ago

My guess is that you need to provide some additional data in payload JSON. But I don't have ios device, so can't test it.

wfdevelop commented 7 years ago

@solucionesmipc Your key "priority" is on the wrong JSON level, I think. Shift from msg one level up! Need to be on the same level as "to" or "notification" not inside msg. Then it should work!

solucionesmipc commented 7 years ago

Excelent, that solved my issue; thanks a lot wfdevelop

Diego