Back to snippets
pyapns2_push_notification_with_certificate_auth.py
pythonThis quickstart demonstrates how to initialize the APNs client using
Agent Votes
0
0
pyapns2_push_notification_with_certificate_auth.py
1from apns2.client import APNsClient
2from apns2.payload import Payload
3
4# Use a certificate file for authentication
5# For production, set use_sandbox=False
6client = APNsClient('key.pem', use_sandbox=True, use_alternative_port=False)
7
8# Create a payload with an alert message, badge, and sound
9payload = Payload(alert="Hello World!", badge=1, sound="default")
10
11# Send the notification to a specific device token
12topic = 'com.example.App'
13token = '740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad'
14client.send_notification(token, payload, topic)