简体   繁体   中英

Send iOS Push Notifications from Google App Engine python

I have been looking everywhere for example code on how to do this from a python written server over GAE - but with no luck.

Can someone please help me with the function to do this? (It should be pretty straight forward I believe).

I use this library, and it works well in my app.
https://github.com/simonwhitaker/PyAPNs

enable ssl in app.yaml

libraries:
- name: ssl
  version: latest

code is like below, token_hex == a push notification token sent from a device. And you have to some variables.

from apns import APNs, Payload
apns = APNs(use_sandbox=use_sandbox, 
        cert_file=path/to/cert.pem',
        key_file=path/to/key-noenc.pem')
payload = Payload(alert='hello', sound="default", badge=1,custom={})
apns.gateway_server.send_notification(token_hex, payload)
for (token_hex, fail_time) in apns.feedback_server.items():
    logging.info(token_hex) 
    logging.info(fail_time)

Maybe you may consider this forked version of PyAPNS that has enhanced message support.
https://github.com/jimhorng/PyAPNs
which means it will catch error response for failure messages and resent the message which are discarded by APNS while sending between failure messages and receiving error response.

Solution:

  • Non-blocking ssl socket connection to send notification without waiting for response.
  • A separate thread for constantly checking error-response from read connection.
  • A sent notification buffer used for re-sending notification that were sent after failed notification, or arbitrary connection close by apns. (Reference to non-blocking apns pull request by minorblend, enhanced message by hagino3000)

Result:

  • Send notification at throughput of 1000/secs
  • In worse case of when 1st notification sent failed, error-response respond after 1 secs and 999 notification sent are discarded by APNS at the mean time, all discarded 999 notifications will be resent without loosing any of them. With the same logic, if notification resent failed, it will resent rest of resent notification after the failed one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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