Search code examples
iosapple-push-notificationspyapns

Sending push notification with pyapns with priority


I'm sending ios notifications through apns with the following code:

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)

is there an option to send it with higher priority? Some users are getting the notifications with a significant delay.


Solution

  • just use "priority" parameter here is sample, but I can`t guarantee that notification will be received immediately.

    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)