[英]iOS push notification not received for Distribution mode
我正在将推送通知集成到我的iOS应用程序中。 我正在按照本教程http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1发送推送。
我可以成功发送推送development mode
。 当我尝试在Distribution mode
从服务器发送推送时,请不要在设备上接收。
我有
一)创建aps_develoment.cer
为发展宗旨和aps_production.cer
分配的目的
b)从keychain导出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
。
我按照上面的教程成功地从终端发送了push in 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个小时。
谢谢
在上面的代码中更改行
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDev.pem');
至
stream_context_set_option($ctx, 'ssl', 'local_cert', 'combineDis.pem');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.