Does anybody know how to get error response from Apple push notification service when enhanced version of protocol is used?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With