【问题标题】:Apple push Notification on sandboxApple 在沙盒上推送通知
【发布时间】:2015-05-06 05:35:25
【问题描述】:

我一直在处理苹果推送通知。该代码第一次正常工作并将通知发送到设备。但在第一次通知间隔一段时间后,它不会第二次发送。我不知道为什么会这样。我正在关闭连接。

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ios.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', '1234567881');

// 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) {
    $response['message'] = "Failed to connect: $err $errstr" . PHP_EOL;
    return $response;
}
$response['error'] = false;
$response['message'] = 'Connected to APNS' . PHP_EOL;


// Create the payload body
$body['aps'] = array(
    'alert' => 'this is from test',
    'sound' => 'default'
);

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', 'de785a64fd2ee4cc4e0adf067856528c846c0f1e4fe30f88694e59f808f9d3ba') . 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;


fclose($fp);

die;

【问题讨论】:

  • 您是否收到任何错误消息
  • 没有错误信息,但有一些资源 ID
  • 由于设备令牌,我遇到了同样的问题。一段时间后,设备令牌被更改并且设备停止接收通知。我不知道为什么。您应该检查设备令牌并尝试相同的代码。它应该可以工作。
  • 嗯,已经检查了设备令牌。令牌是正确的。恐怕是连接关闭问题。连接未正确关闭!

标签: php ios push-notification apple-push-notifications


【解决方案1】:

我使用的正是一些代码,它运行良好。 也许尝试在最后删除“死”。

【讨论】:

    猜你喜欢
    • 2017-06-23
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 2015-01-06
    相关资源
    最近更新 更多