首页 > 解决方案 > 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 推送通知问题的此链接。

https://developer.apple.com/forums/thread/118420

标签: iosfirebase-cloud-messagingapple-push-notifications

解决方案


推荐阅读