我正在尝试从本教程raywenderlich教程中为我的iOS推送应用实现APNS
。
根据描述,我已经做了一切。
运行此命令后
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
我收到一条大消息,显示所有内容都按预期连接。
我现在有两个文件PushChatCert.pem
和PushChatKey.pem
和token_hex = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
所以在PyAPNs之后从服务器I发送推送通知。
在我的python shell中完成所有这些后,它会抛出IOError: [Errno 19] Operation not supported by device
import time
from apns import APNs, Frame, Payload
apns = APNs(use_sandbox=True, cert_file='PushChatCert.pem', key_file='PushChatKey.pem')
# Send a notification
token_hex = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
apns.gateway_server.send_notification(token_hex, payload)
File "/Library/Python/2.7/site-packages/apns.py", line 544, in send_notification
self.write(self._get_notification(token_hex, payload))
File "/Library/Python/2.7/site-packages/apns.py", line 273, in write
return self._connection().write(string)
File "/Library/Python/2.7/site-packages/apns.py", line 254, in _connection
self._connect()
File "/Library/Python/2.7/site-packages/apns.py", line 230, in _connect
self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 891, in wrap_socket
ciphers=ciphers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 509, in __init__
self._context.load_cert_chain(certfile, keyfile)
IOError: [Errno 19] Operation not supported by device
在我的终端上运行此评论后
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
我收到了如下委托问题
depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
verify error:num=20:unable to get local issuer certificate
所以我下载了entrust_2048_ca.cer
文件并保存在同一个文件夹中,然后从我正在运行的终端
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -CAfile entrust_2048_ca.cer -cert PushChatCert.pem -key PushChatKey.pem
然后问题已经解决,但如何在PyAPNs
中执行?
答案 0 :(得分:1)
问题已经解决了。这是一个SSL安全问题,因为该python无法访问该文件的文件目录。
我正在关注本教程apple-push-notification-services。
如本教程中所述,在创建aps_development.cer
文件后,我正在执行这些操作以获取.pem文件
$ openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem
Convert the private key’s .p12 file into a .pem file:
$ openssl pkcs12 -nocerts -out PushChatKey.pem -in PushChatKey.p12
Enter Import Password:
MAC verified OK
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
完成所有操作后,我有PushChatKey.pem
和PushChatCert.pem
个文件并使用这些文件我无法将推送通知发送到我的设备PyAPNs
apns = APNs(use_sandbox=True, cert_file='PushChatKey.pem', key_file='PushChatCert.pem')
最后,我从一开始就尝试了这些证书创建,但这次是在其他一些教程
之后创建下载为名为aps_developer_identity.cer
的SSL证书后。双击它以将其安装在Keychain Access应用程序中。 SSL证书将由您的提供商应用程序使用,以便它可以联系APN以向您的应用程序发送推送通知。
从本地Mac和“登录”钥匙串启动Keychain Assistant,按“证书”类别进行过滤。您将看到一个名为“Apple Development iOS Push Services”的可扩展选项:
展开此选项,然后右键单击“Apple Development iOS Push Services” - &gt;导出“Apple Development iOS推送服务......”。将其保存为apns-dev-cert.p12
文件,您可以访问它。
现在从apns-dev-cert.p12
您使用终端
openssl pkcs12 -in apns-dev-cert.p12 -out apns.crt.pem -clcerts -nokeys
openssl pkcs12 -in apns-dev-cert.p12 -out apns.key.pem -nocerts -nodes
如果您想创建single .pem
openssl pkcs12 -in apns-dev-cert.p12 -out apns_development.pem -nodes -clcerts
现在将这些apns.crt.pem
和apns.key.pem
文件与PyAPNs一起使用,它就像魔法一样。
仔细创建provision profile
。
感谢。