【发布时间】:2011-12-29 06:43:14
【问题描述】:
我正在使用 this tutorial 来学习推送通知。
<?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 代码,因为当我在远程服务器上使用简单的 apns 时,它会发送推送通知。 收到通知的时间是 6 到 7 小时。我认为这是由于我的设备端的网络问题。 但现在它在生产配置文件上运行了 2 天后工作正常。现在通知在我的设备上传送不需要时间,但在某些设备上需要 30 秒到 5 分钟。
如果您的设备上也没有收到来自其他应用程序的推送通知,则可能还有一个问题,那么您应该检查您的 DNS 是否有连接。
【问题讨论】:
-
这是服务器端实现部分,iphone 应用部分呢。你可以查看这个教程mobiforge.com/developing/story/…raywenderlich.com/3443/…
-
我遵循 raywenderlich for iphone 实施。用于获取设备令牌
-
问题不在我的个人资料中。可能错误是我正在使用的 php 代码,因为当我在远程服务器上使用简单的 apns 时,它会发送推送通知。收到通知的时间是 6 到 7 小时。我认为这是由于我的设备端的网络问题。但现在它在生产配置文件上运行了 2 天后工作正常。现在通知不需要时间在我的设备上传递,但在某些设备上需要 30 秒到 5 分钟。
-
你能告诉我你在哪个类中编写了你的推送通知委托方法。
-
我在Application委托类中写的
标签: php objective-c iphone push-notification apple-push-notifications