0
votes

I'm using below PHP code to send push notification to Android and iOS devices using Firebase REST API. Push notifications are coming fine in Android device. But it is not coming in iOS device.

Meanwhile, when I send the notification from the Firebase console, both devices are receiving it. Did I miss anything in my API implementation?

$data = array("to" => "/topics/news",
              'priority' => '10',
              'notification' => array('body' => $msg));

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

try {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");

    curl_setopt($ch, CURLOPT_POST, true);                                                                  
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $ouput = curl_exec($ch);

    if ($ouput === false) {
        throw new Exception(curl_error($ch), curl_errno($ch));
    }

    $response = curl_getinfo($ch);
} catch(Exception $e) {}
1
Can you print out how your payload is interpreted? If I'm reading it right, it would be showing a payload where your notification is inside the data? Also, try setting the priority to high instead of 10. - AL.
Yes. After setting priority to high it is working fine. If you post it as an answer, i'll accept it. - user10
I'll go ahead and do that. - AL.

1 Answers

0
votes

You should set your priority to high instead of 10.

When using GCM/FCM, the only valid values for priority are normal and high which is equal to 5 and 10 for iOS APNs, as was mentioned here:

Sets the priority of the message. Valid values are "normal" and "high." On iOS, these correspond to APNs priorities 5 and 10.