Last active
December 15, 2015 23:29
-
-
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.
This file contains hidden or 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, 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) |
This file contains hidden or 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, 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