forked from djacobs/PyAPNs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apns-send
executable file
·45 lines (31 loc) · 1.32 KB
/
apns-send
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
from apns import APNs, Payload
import optparse
parser = optparse.OptionParser()
parser.add_option("-c", "--certificate-file",
dest="certificate_file",
help="Path to .pem certificate file")
parser.add_option("-k", "--key-file",
dest="key_file",
help="Path to .pem key file")
parser.add_option("-p", "--push-token",
dest="push_token",
help="Push token")
parser.add_option("-m", "--message",
dest="message",
help="Message")
parser.add_option("-s", "--sandbox",
action="store_true", dest="sandbox", default=False,
help="Use apple sandbox (dev push certificates)")
options, args = parser.parse_args()
if options.certificate_file is None:
parser.error('Must provide --certificate-file')
if options.push_token is None:
parser.error('Must provide --push-token')
if options.message is None:
parser.error('Must provide --message')
apns = APNs(use_sandbox=options.sandbox, cert_file=options.certificate_file, key_file=options.key_file)
# Send a notification
payload = Payload(alert=options.message, sound="default", badge=1)
apns.gateway_server.send_notification(options.push_token, payload)
print("Sent push message to APNS gateway.")