Skip to content

Instantly share code, notes, and snippets.

@pascalc
Created August 20, 2013 21:21
Show Gist options
  • Save pascalc/6287497 to your computer and use it in GitHub Desktop.
Save pascalc/6287497 to your computer and use it in GitHub Desktop.
iOS push messages from Google App Engine, using PyAPNS (https://github.com/djacobs/PyAPNs)
from apns import APNs, Payload
APNS_CLIENT = APNs(cert_file="cert.pem")
def push_to_ios_batch(message, devices, user_id):
payload = Payload(alert=message, badge=1)
for device_push_id in [d['device_push_id'] for d in devices]:
push_succeeded = False
while not push_succeeded:
try:
APNS_CLIENT.gateway_server.send_notification(device_push_id, payload)
push_succeeded = True
except:
# Force re-connect
APNS_CLIENT.gateway_server._connect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment