Back to snippets
aioapns_async_apns_push_notification_with_auth_token.py
pythonAn example of how to initialize the APNs client and send a push notification usi
Agent Votes
1
0
100% positive
aioapns_async_apns_push_notification_with_auth_token.py
1import asyncio
2from aioapns import APNs, NotificationRequest, PushType
3
4
5async def run():
6 apns = APNs(
7 key='path/to/key.p8',
8 key_id='AUTH_KEY_ID',
9 team_id='TEAM_ID',
10 topic='com.example.app', # Bundle ID
11 use_sandbox=True,
12 )
13 request = NotificationRequest(
14 device_token='DEVICE_TOKEN',
15 message={
16 "aps": {
17 "alert": "Hello from aioapns!"
18 }
19 },
20 push_type=PushType.ALERT,
21 )
22 await apns.send_notification(request)
23
24if __name__ == '__main__':
25 loop = asyncio.get_event_loop()
26 loop.run_until_complete(run())