使用http/2push提供程序api在ios、osx和safari上提供简单、灵活和快速的apple推送通知。
pyapns-client的Python项目详细描述
使用HTTP/2推送程序API,在iOS、OSX和Safari上推送简单、灵活和快速的苹果推送通知。
功能
- 使用新的Apple APNS http/2协议
- 支持新的ios 10功能,如折叠id、字幕和可变通知
- 支持到APN的持久连接
注意事项
- 仅适用于Python3.5及更高版本
安装
使用pip安装:
pip install pyapns_client
用法
frompyapns_clientimportAPNSClient,IOSPayloadAlert,IOSPayload,IOSNotification,APNSException,UnregisteredExceptioncli=APNSClient(mode=APNSClient.MODE_DEV,client_cert='/your/path.pem')alert=IOSPayloadAlert(body='body!',title='title!')payload=IOSPayload(alert=alert)notification=IOSNotification(payload=payload,priority=IOSNotification.PRIORITY_LOW)try:cli.push(notification=notification,device_token='your_token')exceptAPNSExceptionase:ife.is_device_error:ifisinstance(e,UnregisteredException):# device is unregistered, compare timestamp (e.timestamp_datetime) and remove from dbpasselse:# flag the device as potentially invalidpasselife.is_apns_error:# try again laterpasselife.is_programming_error:# check your code# try again laterpasselse:# everything is okpass