プッシュ通知を送信しようとしていますが、APNS から次の応答が返されます: Resource id #3。これは、トピックが欠落していることを意味します。2 番目の Apple ドキュメントですよね? 「話題」とは?私は何を間違っていますか?証明書を再作成しましたが、問題ないと思います。「話題」が何かわかりません。
以下は私のサーバーphpです:
<?php
$deviceToken = $_POST["deviceToken"];
// Put your private key's passphrase here:
$passphrase = 'password';
// Put your alert message here:
$message = 'My first push notification!';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.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 $fp;
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
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
{
echo 'Message not delivered' . PHP_EOL;
echo $fp;
}
else
{
echo 'Message successfully delivered' . PHP_EOL;
echo $fp;
}
// Close the connection to the server
fclose($fp);
?>
サーバーは成功してメッセージを送信しますが、前に言ったようです... APNSの応答を受け取ります:
リソース ID #3。
それは何でしょうか?
編集済み私が直す。問題は URL でした... gateway.sandbox.push.apple.com に変更しました。開発のURLです!