user10 user10 - 1 year ago 266
iOS Question

Firebase Cloud Messaging - PHP REST API not working on iOS

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, "");

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) {}

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download