Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 565
Lior Z Avatar asked Jan 29 '26 19:01

Lior Z


1 Answers

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)
like image 175
yosuke Avatar answered Jan 31 '26 10:01

yosuke