gpt4 book ai didi

python - 为 iOS 发送 9000/s 推送通知

转载 作者:行者123 更新时间:2023-11-29 13:10:43 24 4
gpt4 key购买 nike

我的系统有大约 10000 个 iOS 用户,我想向他们发送推送通知但不需要花时间,因为我可能会在 5 分钟或更短的时间内为同一用户发送另一条消息,我之前读过这个答案,它也是在 Apple 网站上创建的:

Push Notification Throughput and Error Checking

There are no caps or batch size limits for using APNs. The iOS 6.1 press release stated that APNs has sent over 4 trillion push notifications since it was established. It was announced at WWDC 2012 that APNs is sending 7 billion notifications daily.

If you're seeing throughput lower than 9,000 notifications per second, your server might benefit from improved error handling logic.

但是我一个一个发通知的时候不知道怎么发9000/s的消息。

我正在使用 Python (PyAPNs),这是我的代码:

from apns import APNs,Payload
result = execute("SELECT token_hex FROM `Users`")
for row in result:
token_hex = row['token_hex']
apns = APNs(use_sandbox=False, cert_file='Cert.pem', key_file='CertKey.pem')
payload = Payload(alert="Message",badge=1,sound='default')
apns.gateway_server.send_notification(token_hex, payload)

我要在 30 多分钟内发送给 10000 个用户...

那么我的代码有什么问题,或者我该怎么做才能在更短的时间内发送通知...

提前致谢

最佳答案

我不懂 python,但查看您的代码,您似乎在不必要地重复调用。您应该使用相同的连接来发送所有通知。

也许你应该尝试这样的事情:

from apns import APNs,Payload
result = execute("SELECT token_hex FROM `Users`")
apns = APNs(use_sandbox=False, cert_file='Cert.pem', key_file='CertKey.pem')
payload = Payload(alert="Message",badge=1,sound='default')
for row in result:
token_hex = row['token_hex']
apns.gateway_server.send_notification(token_hex, payload)

这是假设您向所有设备发送相同的通知负载。

关于python - 为 iOS 发送 9000/s 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17450255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com