且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iPhone推送通知证书

更新时间:2023-02-27 11:32:50

如果我正确理解你的问题,答案是否定的,它不应该是同一个文件。我将详细解释整个过程,希望这将澄清情况(以及接下来需要做什么)。

If I understand your question correctly, the answer is no, it should not be the same file. I'll explain the entire process in detail and hopefully that will clarify the situation (and what you need to do next).

当您启用推送通知时,您需要做四件事:

When you enable push notifications, you need to do four things:


  1. 创建私钥/公钥对。

  2. 创建证书签名请求(CSR),使用您的私钥签名。

  3. 将CSR提交给Apple并下载签名证书。

  4. 创建包含证书的文件和私钥,用于验证每个APN请求。

  1. Create a private/public key pair.
  2. Create a certificate signing request (CSR), signed with your private key.
  3. Submit the CSR to Apple and download a signed certificate.
  4. Create a file containing your certificate and private key, for validating each APN request.

一些要点:


  • 我建议您使用不同的密钥进行开发(沙箱)和生产APN。如果您要向不同的应用程序发送通知,则可以重新使用这些密钥,但如果您不在开发和生产之间重复使用密钥则更安全。

  • 您提交的文件到配置门户是证书请求。每个证书都有一个CSR文件。您将为每个应用程序(bundleID)创建两个CSR;一个用于开发,一个用于生产。使用您的开发密钥创建的CSR应提交进行开发,并且应使用生产密钥创建CSR以进行生产。

    注意:保留CSR文件。您不必拥有它们,但是当您需要重新发送证书请求时,它将为您节省一些时间。

  • 提交CSR后,您将能够下载实际证书。他们还没有准备立即,所以给Apple一分钟左右,然后刷新浏览器。 CSR和证书之间的区别很重要:证书由Apple签署;它验证您发送推送通知的能力。下载证书并将其加载到您的钥匙串中(双击即可)。

    注意:没有您的私钥,证书是无用的;因此,如果您切换计算机,则需要安全地导出私钥。

  • 任何发送APN请求的计算机都需要私钥和证书。您可以使用Keychain Access将它们导出为单个.p12文件。 (我将我的名字命名为MyAppCertKey.p12,表明该文件包含证书密钥。)

  • 最后,我写了详细的解释测试/验证与Apple服务器(来自终端)的通信。这有点复杂,因为您需要为 openssl 设置一些根证书以进行验证;但是,它会告诉您是否与服务器正确通信,而不需要对接收应用程序本身进行任何操作。

  • I recommend you use different keys for development (sandbox) and production APN. You can re-use the keys if you are sending notifications to different apps, but it is safer if you don't re-use keys between development and production.
  • The file you "submit" to the provisioning portal is the certificate request. You will have one CSR file for each certificate. You will create a two CSR for each app (bundleID); one for development, one for production. The CSR created with your development key should be submitted for development and the CSR created with your production key should be submitted for production.
    Note: Keep the CSR files. You don't have to have them, but it will save you some time when you need to re-send the certificate requests.
  • After submitting your CSRs, you will be able to download the actual certificates. They aren't ready immediately, so give Apple a minute or so and then refresh your browser. The difference between the CSR and a certificate is important: the certificate is signed by Apple; it validates your ability to send push notifications. Download the certificates and load them into your keychain (double clicking is fine).
    Note: the certificate is useless without your private key; so you will need to safely export your private key if you switch computers.
  • Any computer sending an APN request will need both the private key and the certificate. You can export them as a single .p12 file using Keychain Access. (I name mine MyAppCertKey.p12 to indicate that the file contains both the certificate and the key.)
  • Last, I wrote up a detailed explanation on testing / verifying communication with Apple's servers (from the terminal). It's a little complicated since you need to have some root certificates set up for openssl to validate against; however, it will tell you if you are communicating correctly with the servers, without requiring any work on the receiving app itself.

无法连接到APNS沙盒服务器

希望有所帮助。