【发布时间】:2019-09-21 21:09:38
【问题描述】:
iOS 13 现在要求您为警报或背景添加 apns-push-type 的标头。如何将此添加到我用于发送通知的当前代码中?
多年来我一直使用此解决方案发送推送通知,但我不知道如何添加他们需要的标头。
function sendPushNotification($uid,$title,$message,$action,$type,$id){
$deviceToken = "*************";
$passphrase = '***********';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pem/Certificates.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
// Open a connection to the APNS server
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
//echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => array(
'title' => $title,
'body' => $message,
'action-loc-key' => 'Bango App',
),
'mutable-content'=> 1,
'badge' => 1,
'content-available'=>1,
'sound' => 'oven.caf',
'action' => $action,
'type' => $type,
'id' => $id,
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
fclose($fp);
// Close the connection to the server
}
?>```
【问题讨论】:
-
我也遇到了同样的问题,你找到解决办法了吗?如果你发现了什么,请分享。
标签: php apple-push-notifications ios13