在生产应用程序中使用 APNS

Working with APNS in production apps

在小型环境和低音量通知中使用 APNS 不是问题。

问题(至少对我而言)是如何在大量通知环境中处理 APNS 限制。

APNS 有一些限制(设计使然),这使得它更难顺利工作

  1. 持续连接和断开 APNS 可能被视为 DOS 攻击。这让我相信我需要每隔几秒批量发送一次通知,而不是 "real time" 发送

  2. 不知道通知是否已到达或发送成功。只有出错时才返回,返回时可能不会立即返回。

  3. 当通知导致错误(例如由于错误的令牌)时,APNS 将关闭连接,并且该批次中的其余通知将不会发送到它们的目的地,但有些可能仍会发送到 APNS,然后永远丢失(没有关于成功的反馈,因此不知道它们发生了什么)。

实际生产应用程序如何与 APNS 配合使用来解决上述问题?我是否应该保存我发送的所有通知并为每个通知检查是否返回了错误?我应该让他们排队吗?我是否应该面对这样一个事实,即会有不会发送的通知?连接之间的合理时间是多长,这样才算作 DOS 攻击?

(目前我在 Ruby 中使用 Houston 来处理通知)

这是我从 Local and Remote Notification Programming Guide

中找到的

管理连接的最佳实践

You may establish multiple connections to the same gateway or to multiple gateway instances. If you need to send a large number of remote notifications, spread them out over connections to several different gateways. This improves performance compared to using a single connection: it lets you send the remote notifications faster, and it lets APNs deliver them faster.

Keep your connections with APNs open across multiple notifications; don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack. You should leave a connection open unless you know it will be idle for an extended period of time—for example, if you only send notifications to your users once a day it is ok to use a new connection each day.

如您所知,APNS 服务不可靠。您可以使用 亚马逊简单通知服务 (Amazon SNS)。

它是一种快速、灵活、完全托管的推送通知服务,可让您发送单独的消息或将消息分散给大量收件人。 Amazon SNS 使向移动设备用户、电子邮件收件人发送推送通知甚至向其他分布式服务发送消息变得简单且经济高效。 关注下方url了解更多详情......

https://aws.amazon.com/blogs/aws/push-notifications-to-mobile-devices-using-amazon-sns/