簡體   English   中英

Apple APNs 推送通知不起作用

[英]Apple APNs push notification is not working

在過去的 7 年里,我的團隊一直在使用 Apple 推送通知,它就像 Gem 一樣工作。 最近在開發證書和 App Store 證書中生成的構建未收到通知。

通知是從 PHP 代碼發送的。

<?php

// Put your device token here (without spaces):
$deviceToken = '****************';
// Put your private key's passphrase here:
$passphrase = '******';

// Put your alert message here:
$message = 'Hi User!';
//$message =$_REQUEST['message'];
////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'cert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

/* Open a connection to the APNS server*/
 $fp = stream_socket_client(
 'ssl://gateway.push.apple.com:2195', $err,
 $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default'
    );


// 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
echo $result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered' . PHP_EOL;

// Close the connection to the server
fclose($fp);
?>

推送通知結果為成功。 但是應用程序沒有收到通知。 這段代碼有什么新的更新嗎? 在設備上接收通知是否有可能出錯?

如果您使用 p12 或 pem 文件發送推送,則它已停止。

您必須使用使用 P8 文件的新方法

查看以下鏈接了解更多詳情。

https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM