Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Firebase iOS push works in console but not in API

I'm using https://github.com/arnesson/cordova-plugin-firebase/ to receive Google Firebase messages on a ionic based app.

After set certificates, install plugin and setup Firebase account I was able to receive notifications (on both android and ios devices) sended through the Firebase Console.

But when I send through the Firebase API (https://firebase.google.com/docs/cloud-messaging/http-server-ref) only android devices receive the notification. I'm using the following code:

$data = Array
(
    [to] => <token>
    [notification] => Array
        (
            [title] => My Title
            [text] => Notification test
            [sound] => default
            [vibrate] => 1
            [badge] => 0
        )

)

$jsonData = json_encode($data);
$ch     = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array(
  'Content-Type: application/json',
  "Authorization: key=".$gcmApiKey
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

$result = curl_exec($ch);
curl_close($ch);

echo $result;

No errors are returned:

{"multicast_id":904572753471539870406,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1477063422322568734%3d5c78243d5c7824"}]}

What can be wrong?

like image 599
Arivan Bastos Avatar asked Oct 21 '16 17:10

Arivan Bastos


1 Answers

For iOS, try adding in parameter priority set to high and content_available set to true in your payload.

See the parameter details here.

like image 152
AL. Avatar answered Oct 25 '22 00:10

AL.