当其他用户向他发送消息时,我正在使用苹果推送通知向他发送通知。 我使用的代码在开发模式下运行良好,但是当我将我的应用程序上传到应用程序商店时,我的用户没有收到通知。
所以我根据本教程(我用于生产的相同教程)创建了一个新的 pem 文件(但具有生产认证):
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
**在apple member center中,Distribution模式的通知开启
但是现在有一个问题,当服务器尝试发送通知时:
fwrite(): SSL: Broken pipe'
我的代码:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'file.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)
return;
$message = "Hello world";
$deviceToken = "token...";
// 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));
// Close the connection to the server
fclose($fp);
我不知道该怎么办,我在网上搜索了所有的解决方案,但没有很好的结果。 希望你能帮助我,谢谢 =)
最佳答案
您正在向沙箱服务器发送通知 - ssl://gateway.sandbox.push.apple.com:2195
你应该将它发送到生产服务器 ssl://gateway.push.apple.com:2195
关于IOS 推送通知在生产环境中不起作用 : fwrite(): SSL: Broken pipe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24659986/