Skip to content

Commit 93f28d1

Browse files
committed
in which multiple apps are provisioned at startup
1 parent 300273f commit 93f28d1

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

example_conf.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"port": 7077,
3+
"autoprovision": [
4+
{
5+
"app_id": "sandbox:com.ficture.ficturebeta",
6+
"cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta.pem",
7+
"environment": "sandbox",
8+
"timeout": 15
9+
},
10+
{
11+
"app_id": "production:com.ficture.ficturebeta",
12+
"cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta.pem",
13+
"environment": "production",
14+
"timeout": 15
15+
},
16+
{
17+
"app_id": "sandbox:com.ficture.ficturebeta2",
18+
"cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta2.pem",
19+
"environment": "sandbox",
20+
"timeout": 15
21+
},
22+
{
23+
"app_id": "production:com.ficture.ficturebeta2",
24+
"cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta2.pem",
25+
"environment": "production",
26+
"timeout": 15
27+
},
28+
{
29+
"app_id": "sandbox:com.ficture.ficturebeta3",
30+
"cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta3.pem",
31+
"environment": "sandbox",
32+
"timeout": 15
33+
},
34+
{
35+
"app_id": "production:com.ficture.ficturebeta3",
36+
"cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta3.pem",
37+
"environment": "production",
38+
"timeout": 15
39+
}
40+
]
41+
}

example_tac.tac

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1+
# CONFIG FILE LOCATION
2+
# relative to this file or absolute path
3+
4+
config_file = 'example_conf.json'
5+
6+
# you don't need to change anything below this line really
7+
18
import twisted.application, twisted.web, twisted.application.internet
2-
import pyapns.server
9+
import pyapns.server, pyapns._json
10+
import os
11+
12+
with open(os.path.abspath(config_file)) as f:
13+
config = pyapns._json.loads(f.read())
314

415
application = twisted.application.service.Application("pyapns application")
516

617
resource = twisted.web.resource.Resource()
7-
resource.putChild('', pyapns.server.APNSServer())
18+
service = pyapns.server.APNSServer()
19+
20+
# get automatic provisioning
21+
if 'autoprovision' in config:
22+
for app in config['autoprovision']:
23+
service.xmlrpc_provision(app['app_id'], app['cert'], app['environment'],
24+
app['timeout'])
25+
26+
# get port from config or 7077
27+
if 'port' in config:
28+
port = config['port']
29+
else:
30+
port = 7077
31+
32+
resource.putChild('', service)
833
site = twisted.web.server.Site(resource)
934

10-
server = twisted.application.internet.TCPServer(7077, site)
35+
server = twisted.application.internet.TCPServer(port, site)
1136
server.setServiceParent(application)
12-

0 commit comments

Comments
 (0)