APNS 推送通知不适用于生产 [英] APNS Push Notifications Not Working on Production

查看:30
本文介绍了APNS 推送通知不适用于生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序来从网络服务器发送远程通知.当我在开发模式下测试应用程序时,所有通知都正确到达手机上,在 AppStore 发布后,应用程序不再收到通知.

I created an App to send remote notifications from a web server. When I tested the App in Development Mode all the notifications arrived correctly on the phone, after the AppStore release the app did not receive notifications anymore.

这就是我所做的:

  1. 为生产创建了一个私钥,为开发创建了一个私钥.
  2. 通过传递之前生成的 CertFile 在我的 App ID 上生成两个 SSL 证书.我 100% 确定已正确生成 2 个密钥并正确传递它们以从 AppID 下的开发中心下载 SSL 证书.
  3. 为开发创建了一个文件 .pem,为生产创建了一个文件(通过转换从我的 KeyChain 等中提取的文件 .p12).
  4. 创建了 2 个不同的配置文件,一个用于开发,一个用于生产,连接到步骤 1 的 AppID.
  5. 使用在第 4 步中创建的正确配置文件在构建设置"中对应用进行签名.
  6. 创建了一个网络应用来捕获和存储用户令牌.
  7. 创建了一个 php 页面来测试推送通知发送.

这是我测试的:

  1. 使用沙盒链接上的 telnet 测试了开发生成的 .pem 文件,并获得了成功的答案.
  2. 在生产链接上使用 telnet 测试了生产生成的 .pem 文件,并获得了成功的答案.
  3. 我 100% 确定已将 iPhone 的开发令牌存储在我的网络应用中.
  4. 我 100% 确定已将 iPhone 的生产令牌存储在我的网络应用服务器上.
  5. 我 100% 肯定会通过我的 php 页面将正确的消息传递给 Apple Server(用于开发和生产).
  6. php 页面总是从 Apple Server(开发和生产)返回成功消息.

这是我在 Xcode 上签署应用程序的方式:

Here is how I sign the app on Xcode:

这里是php页面发送通知的代码:

Here is the code of the php page to send notifications:

    $ctx = stream_context_create();

    //stream_context_set_option($ctx, 'ssl', 'passphrase', 'development_pwd');
    //stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck_development.pem');
    //$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); //test

    stream_context_set_option($ctx, 'ssl', 'passphrase', 'production_pwd');
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck_production.pem');
    $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); //production

    echo "<p>Connection Open</p>";
    if(!$fp){
        echo "<p>Failed to connect!<br />Error Number: " . $err . " <br />Code: " . $errstrn . "</p>";
        return;
    } else {
        echo "<p>Sending notification!</p>";    
    }

    $i = 0;

    foreach ($deviceToken as $dt) {
        $dt = str_replace(' ' , '' , $dt);
        $msg = chr(0) . pack('n',32) . pack('H*', $dt) . pack('n',strlen($payload)) . $payload;
        echo "<p>" . $i . " - Message sent: " . $payload . "<br />Token: ". $dt . "<br />***" . $msg . "***</p>";
        $result = fwrite($fp, $msg, strlen($msg));
        $i++;
        if (!$result)
            echo '<p>Message not delivered ' . PHP_EOL . '!</p>';
        else
            echo '<p>Message successfully delivered ' . PHP_EOL . '!</p>';
    }
    fclose($fp);
    echo "<p>Total Notifications Sent: " . $i . "</p>";
    echo "<p>Connection Closed!</p>";
}
?>

结论:我的 PC 上有接收 APNS 推送通知的测试应用程序.我在 App Store 上发布了完全相同的应用,但没有收到 APNS 推送通知.

Conclusions: I have the Test App on my PC that receive APNS Push Notifications. I have the exactly same app released on App Store that not receive APNS Push Notifications.

我真的尽我所能来解决这个问题,并阅读了大约数千页的论坛、stackoverflow 和 Apple 文档.

I realy made everything in my power to fix this issue and read about thousand pages of forums, stackoverflow and Apple Documentations.

我愿意回报所有帮助我找到问题解决方案的人!

推荐答案

您提到的链接是 Sandbox APNS 链接.生产 APNS 链接按照 Apple 文档是:

The link you mentioned is Sandbox APNS link. Production APNS link is as per Apple documentation is:

您在 gateway.push.apple.com 上访问生产环境,出站 TCP 端口 2195.

You access the production environment at gateway.push.apple.com, outbound TCP port 2195.

需要验证的几件事:

  1. 您的 AppId 已启用分发 APNS.
  2. 您已创建分发 APNS SSL 证书并安装在您的构建机器上(用于 App Store 提交).
  3. 您已在服务器上安装了第 2 步中的 SSL 证书.
  4. 您没有错误地使用开发 APNS SSL 证书.

这篇关于APNS 推送通知不适用于生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆