【发布时间】:2017-10-01 00:15:58
【问题描述】:
我想在 php 中使用 firebase 发送推送通知。我的代码适用于 android,但不适用于 ios 设备。
我在这两种情况下都取得了成功:1。
这是我的代码
<?php
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields = array('registration_ids' => $token,
'data' => array('title'=>'Title',
'body'=>$message['message'],
'image'=>$imagepath,
'priority'=>'high'
)
);
$headers = array(
'Authorization:key=AIzaSyBiOCXbU7roG59_**********vWa4Xc' ,
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
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));
$result = curl_exec($ch);
curl_close($ch);
return $result;
?>
反应是
stdClass Object
(
[multicast_id] => 8.5168949472892E+18
[success] => 1
[failure] => 0
[canonical_ids] => 0
[results] => Array
(
[0] => stdClass Object
(
[message_id] => 0:1493801065120413%2d69fd2bf9fd7ecd
)
)
)
【问题讨论】:
-
您收到的 Android 和 iOS 响应与成功消息相同。请检查您的 iOS 应用是否已进行所有设置以接收通知。
-
好的,但是我收到来自 firebase 控制台@Gagan_iOS 的通知
-
好的,但是您了解 iOS 代码吗?我认为 APNS 可能工作正常,但由于一些 iOS 代码错误,通知不可见。 iOS 设备有很多条件。
标签: php android ios firebase firebase-cloud-messaging