IOS 推送通知在生产环境中不起作用 : fwrite(): SSL: Broken pipe

标签 ios push-notification apple-push-notifications

当其他用户向他发送消息时,我正在使用苹果推送通知向他发送通知。 我使用的代码在开发模式下运行良好,但是当我将我的应用程序上传到应用程序商店时,我的用户没有收到通知。

所以我根据本教程(我用于生产的相同教程)创建了一个新的 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/

相关文章:

objective-c - 在 UINavigationBar 中 setBackgroundImage 之后使用 barStyles

ios - 在 Google map 上显示和隐藏用户默认位置标记

ios - 内部类存在于混合框架的自动生成的 header 中

php - 使用 PHP 执行 cURL 发送推送通知

ios - `isRegisteredForRemoteNotifications` 第一次查询时返回 false

ios - 用图像 react 原生 iOS 推送通知

android - 区别是字符串android设备ID或ios

ios - 使用 Parse : show an alert when the app is in background 推送通知

php - base64_decode 返回 null

unicode - APNS 表情符号 unicode\u 和\U