我正在将推送通知集成到我的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)从pushChatCertDev.pem
和aps_development.cer
pushChatCertDis.pem
创建aps_production.cer
d)从combineDev.pem
和pushChatCertDev.pem
创建pushChatKey.pem
。同样从combineDis.pem
和pushChatCertDis.pem
创建了pushChatKey.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。然后我从app商店下载相同的应用程序到我的iPhone 4S。我将php脚本上传到我的服务器,并将combineDev.pem
替换为combineDis.pem
。当我从服务器运行php脚本时显示
Connected to APNS Message successfully delivered
但iPhone 4S没有收到推送。我还尝试将ssl://gateway.sandbox.push.apple.com:2195
替换为ssl://gateway.push.apple.com:2195
,但没有运气。
请帮忙。我被困在这里8-10个小时。
由于
答案 0 :(得分:0)
在上面的代码中更改行
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDev.pem');
到
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDis.pem');