Created
August 20, 2013 21:21
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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