Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple push notification enhanced format

Does anybody know how to get error response from Apple push notification service when enhanced version of protocol is used?

like image 469
iKiR Avatar asked May 05 '26 09:05

iKiR


1 Answers

According to Apple documentation if we are using enhanced version of Push protocol we can get error response from channel, error respose format:

COMMAND(1 byte)|STATUS(1 byte)|ID(4 byte)

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 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)
like image 78
iKiR Avatar answered May 08 '26 11:05

iKiR