我正在使用this tutorial要学习推送通知。推送通知不在iphone上接收
<?php
// Put your device token here (without spaces):
$deviceToken = '1675ba8bb005740bb514222227f861c30230a81e6eed6bb6b8f353c57831341d';
// Put your private key's passphrase here:
$passphrase = '111134';
// 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));
echo 'result =' . $result. PHP_EOL;
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
我也配置推送通知的应用程序。配置推后,我也重新创建配置文件,旧的删除一,安装新的配置文件。 我运行应用程序,它给了我设备ID,然后我连接服务器沙箱和生产发送推送通知与他们的相对推送配置文件,但仍然无法接收我的设备上的推送通知。
我也在我的设备上安装ipusher并检查推送通知。他们来自该应用程序。我注意到
一个奇怪的是,我改变我的应用程序标识和使用任何其他应用程序ID,然后在设备令牌保持相同
现在我的问题是我没有收到我的设备上的推送通知。
问题不在我的配置文件中。可能是错误是我使用的php代码,因为当我在远程服务器上使用easy apns时,它会发送推送通知。 收到的通知时间为6至7小时。我认为这是由于我的设备端的网络问题。 但现在它在生产配置文件2天后正常工作。现在通知没有时间交付我的设备,但在某些设备上需要30秒到5分钟。
可以有更多的一个问题,如果你没有你的设备从其他应用程序在收到推送通知过,那么你应该检查你的DNS进行连接。
这是服务器端实现部分iphone应用程序部分。你可以查看这个教程http://mobiforge.com/developing/story/programming-apple-push-notification-services http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part- 12 – iamsult
我遵循raywenderlich为iphone实施。获取设备标记 –
问题不在我的配置文件中。可能是错误是我使用的php代码,因为当我在远程服务器上使用easy apns时,它会发送推送通知。收到的通知时间为6至7小时。我认为这是由于我的设备端的网络问题。但现在它在生产配置文件的2天后工作正常。现在通知没有时间交付我的设备,但在某些设备上需要30秒到5分钟。 –