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

时间:2017-05-10 05:34:28

标签: php firebase laravel-5.3 firebase-cloud-messaging

我已尝试使用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但未提供答案。

2 个答案:

答案 0 :(得分:1)

你需要一个'通知'用于iOS的json阻止响应

答案 1 :(得分:0)

$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);