我正在向我的 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 的场景。
关于ios - 什么时候不在 IOS 应用程序中使用 APNS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28711399/