【问题标题】:Sending push notification with pyapns with priority使用 pyapns 优先发送推送通知
【发布时间】:2023-03-29 23:15:02
【问题描述】:

我正在使用以下代码通过 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)

是否可以选择以更高的优先级发送?一些用户收到通知的时间很晚。

【问题讨论】:

    标签: ios apple-push-notifications pyapns


    【解决方案1】:

    此处仅使用“优先级”参数作为示例,但我不能保证会立即收到通知。

    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)
    

    【讨论】:

    • 嗨,我得到:'GatewayConnection' 对象没有属性 '_sent_notifications' 作为 apns.py 在 self._sent_notifications += frame.get_notifications(self) 上的错误
    猜你喜欢
    • 2023-03-26
    • 2016-11-13
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多