优先使用 pyapns 发送推送通知

Sending push notification with pyapns with priority

我正在使用以下代码通过 apns 发送 ios 通知:

from apns import APNs, Payload

apns = APNs(cert_file='***.pem',key_file='***.pem')
payload = Payload(alert=message, badge=1)
apns.gateway_server.send_notification(token, payload)

是否可以选择以更高的优先级发送它?部分用户收到通知时出现明显延迟。

只用"priority"这里的参数是示例,但我不能保证通知会立即收到。

import time
from apns import APNs, Frame, Payload

apns = APNs(use_sandbox=True, cert_file='cert.pem', key_file='key.pem')

# Send a notification
token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)

# Send multiple notifications in a single transmission
frame = Frame()
identifier = 1
expiry = time.time()+3600
priority = 10
frame.add_item('b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87', payload, identifier, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)