繁体   English   中英

苹果在沙盒上推送通知

[英]Apple push Notification on sandbox

我一直在研究苹果推送通知。 该代码首次可以正常运行,并将通知发送到设备。 但是它在第一次通知间隔后不会第二次发送。 我不知道为什么。 我正在关闭连接。

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

我恰好使用了一些代码,它可以完美地工作。 也许最后尝试删除“ die”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM