推IOS不起作用

时间:2014-06-04 13:22:55

标签: ios cordova push

我创建了一个PhoneGap应用程序,并使用PushPlugin进行通知。

我创建了我的ck.pem,一切都在开发中。 然后我发布了我的应用程序并创建了ck.pem生产,它不起作用。

这是我的推动功能:

$passphrase = '********';
$message = $titre;

$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);
    var_dump($fp); echo "<br/>";
if (!$fp)
    die("Failed to connect: $err $errstr" . PHP_EOL);

$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default',
    'id' => $id
    );

// Encode the payload as JSON
$payload = json_encode($body);
echo $payload."<br/>";
$ids = get_list_ids_smartphone_ios();
foreach ($ids as $id){
    echo $id."<br/>";
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $id) . pack('n', strlen($payload)) . $payload;
    echo $msg."<br/>";
    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));
    var_dump($result); echo "<br/>";
    if (!$result)
        die('Erreur à l\'envoi d\'une notification push pour IOS');
}

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

结果:

resource(1280) of type (persistent stream) 
{"aps":{"alert":"this is a test","sound":"default","id":13299}}
abc46897b077eec6bb477edabb7a620e9d79a967c0a0d689dbc6c17d10eb9fef
îÄh—°wîÆ»G~Ú»zby©gÀ Ö‰ÛÆÁ}ëŸïl{"aps":{"alert":"this is a test","sound":"default","id":13299}}
int(145) 
ab33c500d0e8ac8211ac7b8834e4053266e65f046aca5af7ae1fa4bc41ca33e5
Ö3ÅÐ謂¬{ˆ4ä2fæ_jÊZ÷®¤¼AÊ3ål{"aps":{"alert":"this is a test","sound":"default","id":13299}}
int(145) 

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在尝试将生产环境用于APNS时,请确保您的应用程序使用的是Ad-Hoc证书,否则它很可能会无声地失败。