Reputation: 59
I am using the PHP code given below to send notification with custom payload through Firebase Cloud Messaging. It is working for Android but not for the iOS.
However, I am able to receive notification sent from firebase cloud messaging console. Kindly advise.
public function send_notification($registatoin_ids, $message, $title, $sound,
$purpose)
{
// Set POST variables
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => array(
"for" => $purpose,
"id" => strtotime("now"),
"message" => $message,
"title" => $title,
"sound" => $sound,
"vibrate" => 1,
"date" => date("D d, M Y h:i A"),
"priority"=>'high',
"content_available"=>false
),
'time_to_live' => 600,
);
$headers = array(
'Authorization: key=' . FCM_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
return $result;
}
Upvotes: 1
Views: 1209
Reputation: 4848
Android and iOS handle Push Notifications differently. While Android will only wake from background when only the data
tag is provided, iOS devices require the notification
tag to deal with notifications received while the app is in the background.
Upvotes: 0