【问题标题】:push notifications are not working after migrating to fcm from gcm从 gcm 迁移到 fcm 后,推送通知不起作用
【发布时间】:2019-09-17 23:38:11
【问题描述】:

我已根据这些指导方针https://developers.google.com/cloud-messaging/ios/ios-migrate-fcm 将我的代码从 apns 迁移到 fcm。更新代码后,推送通知不起作用。

我已经创建了证书 .p12 和 .pem 文件,并使用我之前的 apns 相关代码测试了这两个文件。证书很好,并且在使用旧代码时会向客户端设备发送推送通知。但是当我使用新的 fcm 相关代码测试这些证书时,不会出现推送通知。我还更改了我的服务器端点。我尝试从 firebase 控制台发送通知,它也可以正常工作。

我需要更改我的服务器上的某些内容吗?

【问题讨论】:

  • 您是否在 Firebase 控制台上上传了 .p12?
  • 是的,我做到了,正如我所说,它在 firebase 控制台上工作得非常好
  • 请添加您用来发送通知的fcm代码。

标签: firebase push-notification firebase-cloud-messaging apple-push-notifications


【解决方案1】:

终于解决了问题。我需要更改我的服务器端代码。使用 FCM,服务器端(php 脚本)不再需要 .pem 证书。我所做的是,

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

来源:https://www.cumulations.com/blogs/87/how-to-send-push-notifications-in-php-to-ios-devices-using-fcm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多