【问题标题】:Push IOS don't work推送IOS不工作
【发布时间】:2014-06-04 13:22:55
【问题描述】:

我创建了一个 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) 

感谢您的帮助。

【问题讨论】:

    标签: ios cordova push


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-06-04
      • 1970-01-01
      • 2013-06-20
      • 2014-07-21
      • 2015-07-09
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多