3

iOS用のアプリを開発し、アプリストアで公開しました。プッシュ通知システムは開発ではうまく機能しましたが、今はまったく通知を受け取りません。公開する前に、プッシュを有効にして本番プッシュSSL証明書を構成したアプリIDに関連付けられた開発プロビジョニングプロファイルを生成しました。Production Push SSL証明書をダウンロードしてキーチェーンアクセスにインストールし、それとその秘密鍵をエクスポートして、pemに変換し、一意のpemファイルに統合しました。これをサーバーにアップロードして、phpスクリプトを送信します。通知。phpスクリプトのサーバーを本番サーバー(ssl://gateway.push.apple.com:2195)に変更しました。それでも、スクリプトは通知を送信しているようで、エラーは発生しません。

私が欠けているものは何ですか?

これが私のphpスクリプトです:

<?PHP
/* Here there's Code to retrieve device tokens and put it in a variable $deviceToken from     my online database and then...*/


$message = "Message to be sent";    
$payload = '{
                "aps" : 

                    { "alert" : "'.$message.'",
                      "badge" : 1,
                      "sound" : "bingbong.aiff"
                    } 
            }';

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

// se l'app è già sull'appstore togliere sandbox e lasciare solo gateway.push.apple.com:2195
// invece di gateway.sandbox.push.apple.com:2195
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if(!$fp){
    print "Failed to connect $err $errstrn";
    return;
} else {
    print "Notifications sent! </br>";
}

foreach($devArray as $deviceToken){
    $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack        ("n",strlen($payload)) . $payload;
    print "sending message :" . $payload . "n to device:".$deviceToken."</br>";
    fwrite($fp, $msg);
}
fclose($fp);

?>

4

2 に答える 2

1

「開発プッシュSSL証明書」ではなく、有効な「本番プッシュSSL証明書」を使用してPEMを再生成する必要があるためです。

編集:申し訳ありませんが、間違った行を2回読みました。手順は良さそうです。いつも使用しているphpコードを投稿します。見た目は非常に似ていますが、編集してみることができます。

<?php
      // Passphrase for the private key (ck.pem file)
      // $pass = ”;
      // Get the parameters from http get or from command line
      $message = 'Testo Notifica Push';
      $badge = 1;
      $sound = 'default';

      // Put your private key's passphrase here:
    $passphrase = '';

      // Construct the notification payload
      $body = array();
      $body['aps'] = array('alert' => $message);

      if ($badge)
            $body['aps']['badge'] = $badge;
      if ($sound)
            $body['aps']['sound'] = $sound;

      /* End of Configurable Items */

// Put your device token here (without spaces):
$deviceToken = '20afc981ce9f0c63b5beb83d561d086a1338b2d42dd6defef67e4b7dbabe72b9';

////////////////////////////////////////////////////////////////////////////////

$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;

// Construct the notification payload
      $body = array();
      $body['aps'] = array(’alert’ => $message);

      if ($badge)
            $body['aps']['badge'] = $badge;
      if ($sound)
            $body['aps']['sound'] = $sound;

// 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);
?>
于 2013-03-18T13:30:09.033 に答える
0

プッシュを設定する際に行う最後のステップは、実稼働デバイス トークンと開発デバイス トークンが混在していないことを確認することです。私の場合、私のデータベースでは、プッシュが送信された最初のデバイス トークンは開発用のものでした。これが発生すると、Apple サーバーは接続を切断し、他の通知が送信されないようにします。ありがとうアップル!

于 2013-03-23T07:04:14.140 に答える