Apple推送通知增强格式

时间:2010-10-07 17:53:07

标签: iphone push-notification apple-push-notifications

当使用增强版协议时,有人知道如何从Apple推送通知服务获得错误响应吗?

1 个答案:

答案 0 :(得分:1)

根据Apple文档,如果我们使用增强版Push协议,我们可以从频道,错误设置格式获得错误响应:

  

COMMAND(1字节)| STATUS(1字节)| ID(4   字节)

状态:

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)'

这里是示例代码:

...
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)