简体   繁体   English

使用python和PyAPNS发送iOS推送通知

[英]Sending iOS push notifications with python and PyAPNS

I am trying to figure out how to send push notifications with my python/django app. 我试图弄清楚如何使用我的python / django应用程序发送推送通知。 I found some code online which works when I run it from the terminal but it prompts me to enter in the PEM passphrase manually and I don't know how to set it up so that it just works on it's own. 我在网上找到了一些代码,这些代码在我从终端运行时都可以使用,但是它提示我手动输入PEM密码,而且我不知道如何设置它,因此只能自己运行。

from apns import APNs, Payload

apns = APNs(use_sandbox=True, cert_file='/Users/user/Desktop/Lunch-BoxCert.pem',key_file='/Users/user/Desktop/Lunch-BoxKey.pem')
token = '923...8b4'
# Send a notification
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token, payload)

When I run it by calling python manage.py runserver it blocks until I type the passphrase into the terminal. 当我通过调用python manage.py runserver运行它时,它会阻塞,直到我在终端中输入密码。 Anyway know how to solve this? 反正知道如何解决这个问题?

I ended up just removing the passkeys. 我最终只是删除了密码。

openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

I kind of followed this tutorial here: 我在这里遵循了本教程:

https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/ https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM