推动通知iPhone的问题



我在应用程序中的推送通知有问题。我刚刚开始使用推送通知,所以我不知道我的问题的原因是什么,我在Google中找不到解决方案。因此,我使用了本教程http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12,作为推送通知编程的示例。当我在终端上运行" PHP SimplePush.php"时,一切都很好,我在设备上收到通知。但是,当我将该脚本加载到服务器上并试图从那里运行它时,没有执行操作。只有30秒的等待和消息"无法连接:110连接时间超时"

在这里,我的脚本代码

<?php 
Put your device token here (without spaces):
$deviceToken = '***************';
// Put your private key's passphrase here: 
$passphrase = '**************';
// Put your alert message here:
$message = 'My first push notification!';
////////////////////////////////////////////////////////////////////////////////
$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.sandbox.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;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// 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);

是的,正如newObjective所澄清的,2195&amp;2196端口必须打开。要打开这些端口,您可能会询问Bluehost技术支持团队(票务/聊天),但是您必须在此之前拥有专用的IP地址。

但是还有另一个问题。如果您尝试在设置专用IP地址并打开两个端口后立即发送推送通知消息,则可能会收到相同的"连接时间"错误。您可以通过SSH登录到服务器并运行" Telnet Gateway.sandbox.push.apple.com 2195"命令来测试该问题。如果您收到"连接时间"错误 - 您可以尝试联系BlueHost支持团队,但他们无法解决此问题。

如果您尝试使用2195打开端口的其他任何其他服务器,则还将收到该错误。我与Bluehost支持团队进行了大约10次聊天,开了10张左右的门票,但他们真的无能为力。但是两个星期后,一切都开始工作。我认为这是因为打开专用的IP需要一些时间,但我不确定。无论如何,有趣的是,Bluehost支持团队总是回答问题在Apple方面,即使您告诉他们任何其他具有2195打开端口的服务器也不可用)

最新更新