0

スタック オーバーフローについて投稿するのはこれが初めてなので、この質問が非常に明白である場合はお詫び申し上げます。

iOS アプリのプッシュ通知をセットアップ中ですが、自分のデバイスだけで成功しました。すぐに多くのデバイスでテストする予定ですが、正しい考えがあるかどうか知りたいです。

データベースにすべてのデバイス トークンを保持し、プッシュ通知を送信するときは、データベース内のすべての行 (トークンを含む) を実行し、次のスクリプトを介して送信し、毎回デバイス トークンを置き換えます。自分の秘密鍵を毎回同じに保ちます。これは正しいです?

前もって感謝します!

           // Put your device token here (without spaces):
  $deviceToken = $device; // this will be run through a loop that 
                             changes this variable for every new device


   $passphrase = 'XXXXXXXXX'; //This is mine and remains always
                                the same despite which device... correct?

   // Put your alert message here:
   $message = 'Testing first 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.sandbox.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',
'badge' => 1
);

   // 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;
     else
echo 'Message successfully delivered' . PHP_EOL;

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

0 に答える 0