ios - iOS 13 中的推送通知问题
问题描述
我在我的 iOS 应用程序中使用远程推送通知功能。目前我面临一个奇怪的问题。我正在向 iOS < 13 的设备接收推送通知,但那些 iOS 13 的设备没有收到推送通知。
我在 stackoverflow 和其他平台上进行了很多搜索,发现苹果建议在 iOS 13 中我们需要将“apns-push-type”添加到标题以及有效负载正文中。我已经在服务器端完成了它,在那里我编写了推送通知相关的代码。
我使用 XCode 11 开发了我的应用程序,并使用 FCM(Firebase 云消息传递)服务发送推送通知。
public function pushSurveyorNotificationios(){
$url = "https://fcm.googleapis.com/fcm/send";
$token = 'XXXX-XXXXX-XXXXX';
$serverKey = 'XXXX-YYYYY-ZZZZZ';
$title = "Push Notification Testing";
$body = "Push Notification Testing detail";
$notification = array('title' =>$title , 'body' => $body, 'sound' => 'default', 'badge' => '1');
$arrayToSend = array('to' => $token, 'notification' => $notification, 'apns' => array('headers' => array('apns-push-type' => 'alert')));
$json = json_encode($arrayToSend);
//die($json);
$headers = array();
$headers[] = 'apns-push-type: alert';
$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);
return $response;
}
我用来向设备发送推送通知的上述功能。
我通过 Apple 获得了 iOS 13 推送通知问题的此链接。
解决方案
推荐阅读
- javascript - 如何制作一个搜索列表,其中仅在用户搜索其确切值时才显示该元素
- java - 插入排序错误输出
- python - 通过 PHP/AJAX 提交 python 脚本
- java - 在循环中声明变量(Java 优化测试)
- julia - JuliaDB 在网站后端将其用作生产数据库时缺少什么?
- html - 将 flexbox 中的项目与另一个 flexbox 中的项目对齐
- python - Click() 函数在 python / selenium 中不起作用
- php - 如何确保对后端的 HTTP 请求来自相同的前端来源?
- javascript - Bootstrap 多项目轮播没有响应
- java - 如何使用 Spring 5 webClient 上传文件