【发布时间】:2015-02-22 16:08:24
【问题描述】:
我正在将推送通知集成到我的 iOS 应用中。我正在按照本教程http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 发送推送。
我可以在development mode 上成功发送推送。当我尝试从Distribution mode 上的服务器发送推送时,设备上未收到推送。
我有
a) 创建aps_develoment.cer 用于开发目的和aps_production.cer 用于分发目的
b) 从钥匙串中导出push.p12 并转换为pushChatKey.pem
c) 从aps_development.cer 创建pushChatCertDev.pem 和从aps_production.cer 创建pushChatCertDis.pem
d) 从pushChatCertDev.pem 和pushChatKey.pem 创建combineDev.pem。同样从pushChatCertDis.pem 和pushChatKey.pem 创建combineDis.pem。
我按照上面的教程成功地从终端发送了Development mode 的推送。 PHP 脚本是
<?php
$deviceToken ='eff527a7f5f3127d55a63269538498bff2134c6d7b72e4920809d0a102aa04d6';
// Put your private key's passphrase here:
$passphrase = 'Nopass@1234';
// Put your alert message here:
$message = 'TJS push notification test';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDev.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);
?>
在开发模式下推送发送到 iPhone 4S。然后我从应用商店下载相同的应用到我的 iPhone 4S。我将 php 脚本上传到我的服务器并将combineDev.pem 替换为combineDis.pem。当我从服务器运行 php 脚本时,它显示
Connected to APNS Message successfully delivered
但在 iPhone 4S 上没有收到推送。我还尝试用ssl://gateway.push.apple.com:2195 替换ssl://gateway.sandbox.push.apple.com:2195,但没有运气。
请帮忙。我被困在这里 8-10 个小时。
谢谢
【问题讨论】:
-
您确定用于分发的证书是分发证书吗?
-
还有一件事..推送不可靠..意味着没有 100% 保证他们会交付
标签: php ios push-notification apple-push-notifications