This is my code to send push notifications to mobile app. The code is in Laravel/PHP
$firebaseUrl = FIREBASE_API_URL;
$firebaseApiKey = FIREBASE_API_KEY;
$registrationIds = $deviceIdArray;
$notification = array(
'title' => $notificationTitle,
'message' => $notificationMessage,
'icon' => BASE_URL . 'assets/images/icon/' . $notificationCalamity . '.png',
'body' => $notificationMessage
//"url" =>$firebaseUrl
);
$data = array (
'message' => $notificationMessage,
'additionalData' => $notificationUrl,
'url' => $notificationUrl,
'hazard' => $notificationCalamity,
'quake_id' => $notificationQuakeId
);
$fields = array (
'registration_ids' => $registrationIds,
'notification' => $notification,
'data' => $data
);
//header includes Content type and api key
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $firebaseApiKey
);
//print_r($headers);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $firebaseUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$curlResult = curl_exec($ch);
if ($curlResult === FALSE) {
// if curl response is false, it has failed;
$notificationFcmMessage = 'FCM Send Error: ' . curl_error($ch);
} else {
// if curl response is success, it has been passed
$notificationFcmMessage = $curlResult;
$result = json_decode($curlResult, true);
if(isset($result) && !empty($result) && $result !== null) {
if(intval($result['success']) > 0) {
$notificationSentStatus = SMALL_CHAR_YES;
}
}
}
curl_close($ch);
The code base is sending push notifications to android devices successfully. However, iOS devices are not receiving any notification. I think the issue is with the notification object that I am building. Maybe, something to do with the keys.
How can I fix this?