Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Last active December 15, 2015 23:29
Show Gist options
  • Select an option

  • Save philsturgeon/5340317 to your computer and use it in GitHub Desktop.

Select an option

Save philsturgeon/5340317 to your computer and use it in GitHub Desktop.
Apple Push Notification (APN) is a whiny little bitch which needs a new connection every single time. Using time.sleep(1) will cause the SSH connection to break after 4 or 5 pushes, so you need to make a new connection each time. Yay.
from apns import APNs, Payload, PayloadAlert
import time
tokens = [u'tokenhexabcdef0123456789']
apns = APNs(use_sandbox=True, cert_file='client.pem', key_file='key.pem')
alert = PayloadAlert("", loc_key="FOO", loc_args=['Some Guy'])
payload = Payload(alert=alert, sound="default", badge=1)
for token in tokens:
apns.gateway_server.send_notification(token, payload)
from apns import APNs, Payload, PayloadAlert
import time
tokens = [u'tokenhexabcdef0123456789']
for token in tokens:
apns = APNs(use_sandbox=True, cert_file='client.pem', key_file='key.pem')
alert = PayloadAlert("", loc_key="FOO", loc_args=['Some Guy'])
payload = Payload(alert=alert, sound="default", badge=1)
apns.gateway_server.send_notification(token, payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment