苹果推送通知新的协议不工作 [英] Apple push notification new protocol not working

查看:111
本文介绍了苹果推送通知新的协议不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试苹果推送通知。
我发现,那的APN只接受旧协议格式。新格式的数据传送是行不通的。
这里是旧的(合作)协议的例子。

I am testing Apple push notification. I found, that APNs accept only old protocol format. Sending data with new format is not working. Here is an example with old (working) protocol.

import struct
import socket
import json

payload = {
    'aps': {
        'alert': '123!',
        'sound': 'default'
    }
}
payload = json.dumps(payload)
payload_len = len(payload)
notification = struct.pack('>bh32sh{payload_len}s'.format(payload_len=len(payload)),
                           0, 32, token.decode('hex'),
                           len(payload), payload)

这是例子,它不工作:

import struct
import socket
import json

payload = {
    'aps': {
        'alert': '123!',
        'sound': 'default'
    }
}
payload = json.dumps(payload)
payload_len = len(payload)
struct_format = '>bibh32sbh{payload_len}sbhb'.format(payload_len=payload_len)
notification = struct.pack(struct_format,
                           2, struct.calcsize('bh32sbh{payload_len}sbhb'.format(payload_len=payload_len)),
                           1, 32, token.decode('hex'),
                           2, len(payload), payload,
                           5, 1, 10)

有谁试图发送推送通知新的协议?
如果是的话,我究竟做错了什么?

Does anybody tried to send push notification with new protocol? If yes, what am I doing wrong?

感谢。

推荐答案

您可以考虑使用库增强的消息支持,以减轻你的负担。

You may consider using library with enhanced message support to ease your burden.

  • https://github.com/djacobs/PyAPNs
  • or the fork https://github.com/jimhorng/PyAPNs with more reliable error handling

这将搭上失败消息的错误响应憎恨这是由APNS丢弃该消息。 (故障一个接和右的错误响应接收之前发送邮件时被丢弃)

It will catch error response for failure messages and resent the message which are discarded by APNS. (messages are discarded when sending after failure one and right before error-response is received)

特点:


  • 非阻塞的SSL套接字连接发送通知,而不必等待回应。

  • 对于经常检查从读连接错误响应一个单独的线程。

  • 用于那些被APNS发送失败​​后,通知,或任意连接关闭重新发送通知A发送通知缓冲区。

  • 在1时发送通知的失败更糟糕的情况下,错误响应后1秒和999通知发送的平均时间由APNS被丢弃,丢弃所有999通知将被重新发送,而不失去其中任何回应。用同样的逻辑,如果重发通知失败,它将与故障后反感重发通知其余部分。

性能:


  • 在吞吐量为1000 /秒发送通知

这篇关于苹果推送通知新的协议不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆