何时不在 IOS 应用程序中使用 APNS?

When not to use APNS in an IOS app?

我正在向我的 iOS 应用添加推送通知服务。我知道我可以使用 APNS 或其他方 "Pusher"。在这个阶段,我只有一个 iOS 模型的应用程序。为什么使用 Pusher 优于 APNS?它与流量类型或流量数量有关吗?应用程序空闲或在后台时的通知警报是否只能通过 APNS 实现?

Why is it advantageous to use Pusher over APNS?

速度

在大多数情况下,当应用程序已经打开时,对于应用程序内通知,Pusher 更好。由于 Pusher 通过 WebSocket 连接与服务器保持持久连接,因此传递消息 (<250ms) 的速度将比原生推送通知更快。

应用程序内负载访问

使用 Pusher,您还可以直接访问应用程序中消息的负载,并且负载可以完全自定义。我不确定应用程序是否可以直接访问推送通知中的消息负载(我想澄清一下)。

易于使用

我个人的看法是,与发送推送通知相比,使用 Pusher 触发事件和接收带有消息负载的事件要容易得多。

使用 Pusher,您在服务器上有类似于以下的代码:

pusher.trigger('my-channel', 'my-event', {some:'data'});

在客户端,您的代码类似于:

self.client = [PTPusher pusherWithKey:@"YOUR_APP_KEY" delegate:self];
[self.client connect];

PTPusherChannel *channel = [self.client subscribeToChannelNamed:@"my-channel"];

[channel bindToEventNamed:@"my-event" handleWithBlock:^(PTPusherEvent *channelEvent) {
  // channelEvent.data is a NSDictianary of the JSON object received
}];

Does it relate to the type of traffic,or the quantity of traffic ?

延迟

与上述速度优势一样,如果您发送频繁的数据,您还将受益于 Pusher 的持久 WebSocket 连接。

有效负载大小

在 iOS 8 及更高版本中,通知的最大负载大小为 2 KB (source)。 Pusher 消息的最大负载为 10 KB。

Are notification alerts when the app is idle or in the background only possible with APNS ?

是的。

我不是 100% 确定 Pusher 是否可以做到这一点(调查待定)。所以,这可能是原生 Push Notifications 优于 Pusher 的场景。