Apple 推送通知新协议不起作用 [英] Apple push notification new protocol not working

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

问题描述

我正在测试 Apple 推送通知.我发现,APNs 只接受旧的协议格式.以新格式发送数据不起作用.这是旧(工作)协议的示例.

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)

这是一个不起作用的例子:

And here is example, which doesn't work:

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.

它会捕获失败消息的错误响应,并重新发送被 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 关闭任意连接.
  • 更糟糕的情况是,当第一个通知发送失败,1 秒后错误响应响应,同时发送的 999 通知被 APNS 丢弃,所有丢弃的 999 通知将重新发送而不会丢失任何一个.同理,如果通知重发失败,会在失败后重发剩余的重发通知.

性能:

  • 以 1000/秒的吞吐量发送通知

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

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