使用 FCM 推送通知 IOS
Posted
技术标签:
【中文标题】使用 FCM 推送通知 IOS【英文标题】:push notifications IOS using FCM 【发布时间】:2017-03-07 10:33:33 【问题描述】:我正在使用 FCM 向 ios 应用程序发送推送通知,IOS 开发人员为我提供了设备令牌和 SERVER_KEY,我在 google 上搜索并尝试了不同的解决方案,但对我没有任何效果,所以让我知道我的代码有什么问题,获取错误 “multicast_id”:8569689262516537799, “成功”:0, “失败”:1, “canonical_ids”:0, “结果”: [ “错误”:“无效注册” ] 提前致谢
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
//The device token.
$token = "c2420d68a0838d8fb6b26ef06278e899de73a149e93c9fe13df11f70f3dd5cc1"; //token here
//Title of the Notification.
$title = "Carbon";
//Body of the Notification.
$body = "Bear island knows no king but the king in the north, whose name is stark.";
//Creating the notification array.
$notification = array('title' => $title, 'text' => $body);
//This array contains, the token and the notification. The 'to' attribute stores the token.
$arrayToSend = array('to' => $token, 'notification' => $notification, 'priority' => 'high');
//Generating JSON encoded string form the above array.
$json = json_encode($arrayToSend);
//print_r($json); die();
//Setup headers:
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key=AAAAx6P1Nz0:APA91bEqkVCA9YRw9gpUvmF8UOVrYJ5T8672wfS_I7UAT3dA0g1QS7z-Z4fpn8JMiJ5kFRz9ZGc2K64hKZG-4__PAUqm733hqNDuFCDv9'; // key here
//Setup curl, add headers and post parameters.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//Send the request
$response = curl_exec($ch);
//Close request
print_r($response);
curl_close($ch);
//return $response;
【问题讨论】:
【参考方案1】:您发送的令牌号很可能是错误的。尝试 "/topics/all" 这将向所有注册用户发送通知。
【讨论】:
以上是关于使用 FCM 推送通知 IOS的主要内容,如果未能解决你的问题,请参考以下文章