Laravel 使用 Firebase 的 FCM 推送通知无法在 iOS 上运行,但可以在 Android 上运行

Laravel FCM push notification with Firebase not working on iOS, but fine with Android

我已经尝试使用 Laravel 的 Firebase 通知向 IOS 和 Android 设备发送通知。

但 IOS 设备未收到通知,但 Android 设备工作正常。

那么我的脚本有什么问题?

我试过以下,

$firebase = new \Firebase();
$push = new \Push();

// optional payload

$payload = array();
$payload['team'] = 'India';
$payload['score'] = '5.6';

// notification title
$title = Input::get('title');
// notification message

$message = Input::get('message');

// push type - single user / topic
$push_type = Input::get('push_type');

// whether to include to image or not
$include_image = Input::get('include_image') ? TRUE : FALSE;
$include_image = TRUE;
$push->setTitle($title);
$push->setMessage($message);

if ($include_image) {
   $push->setImage('http://api.androidhive.info/images/minion.jpg');
} else {
   $push->setImage('');
}
$push->setIsBackground(FALSE);
$push->setPayload($payload); 

$json = '';
$response = '';

if ($push_type == 'topic') {
   $json = $push->getPush();
   $response = $firebase->sendToTopic('global', $json);
} else if ($push_type == 'individual') {
   $json = $push->getPush();
   $regId = Input::get('regId');
   $response = $firebase->send($regId, $json);
}

我已参考 this question 但没有提供答案。

你需要一个 'notification' json 块 iOS 来响应

$url = "https://fcm.googleapis.com/fcm/send";

$token = "";

$serverKey = '';

$title = "Title";

$body = "Body of the message";

$notification = array('title' =>$title , 'text' => $body, 'sound' => 'default', 'badge' => '1');

$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
$json = json_encode($arrayToSend);

$headers = array();

$headers[] = 'Content-Type: application/json';

$headers[] = 'Authorization: key='. $serverKey;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST,

"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//Send the request

$response = curl_exec($ch);
//Close request

if ($response === FALSE) {

die('FCM Send Error: ' . curl_error($ch));

}
curl_close($ch);