Improved Apple push formatting format

Does anyone know how to get an error response from the Apple push push service when using the extended protocol version?

+3
source share
1 answer

According to Apple's documentation, if we use an extended version of the Push protocol, we can get an error response from the channel, the format of the error is:

TEAM (1 byte) | STATUS (1 byte) | ID (4 bytes)

statuses:

0: 'No errors encountered'
1: 'Processing error'
2: 'Missing device token'
3: 'Missing topic'
4: 'Missing payload'
5: 'Invalid token size'
6: 'Invalid topic size'
7: 'Invalid payload size'
8: 'Invalid token'
255: 'None (unknown)'

here is an example code:

...
socket = SSLSocket (
    socket.socket()
    , ssl_version = ssl.PROTOCOL_SSLv3
    , certfile
)

socket.connect(apnsHost, apnsPort)

len_written = connectionContext.write(socket)

errors = []

# Wait for input from socket
inputready = select.select ([socket], [],[], 1)[0]

if inputready:
        replyBlock = channel.recv (6)

        errors = [] #will be filled with error responses
        while replyBlock:
            #error-response packet
            #COMMAND(1)|STATUS(1)|ID(4)
            command, status, id = struct.unpack_from('!BBL', replyBlock)

            if status != 0:
                errors.append((command, status, id))                

            replyBlock = channel.recv (6)
+1
source

Source: https://habr.com/ru/post/1768476/


All Articles