iOS应用程序与服务器实时更新:套接字(使用流)或苹果推送通知服务?

问题描述:

我试图做的是iOS 5应用程序,具有实时的东西来自服务器。它只会使用这些虽然应用程序正在运行。

I'm trying to make an iOS 5 app that features real-time things coming from the server. It will only use these whilst the app is running.

要让它实时轮询没有我一直在评估两种设计路线:

To make it real-time without polling I have been evaluating two design routes:



创建从应用插座到服务器上,并通过流交换信息。


  • 优点:的比较简单,不涉及第三方。

  • 缺点:的电池寿命流失。

  • 有关如何这可能工作的概述,请
    这项优秀教程:
    http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server

  • Pros: Relatively simple and would not involve a 3rd party.
  • Cons: Battery life drain.
  • For an overview of how this might work, check out this excellent tutorial: http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server

使用标准的HTTP与服务器进行通信,并与来自应用的每个请求让服务器知道他们正在查看的内容。如果新的东西可用于用户,发送一个苹果推送通知(不可见警报),以便让应用程序知道它可以去下载新的东西。


  • 优点:的不开放了一个新的TCP连接,所以电池寿命不必要倒掉

  • 缺点:的感觉就像一个可怜的黑客

  • 在的APN官方的文档http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html

  • Pros: Not opening up a new TCP connection, so battery life not drained unnecessarily.
  • Cons: Feels like a poor hack.
  • The official docs on APNs http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html



我认为一个插座将要走的道路,但在此之前我承诺给它,我想第二个意见,因为这是我第一次做了这样的事!


I think a socket would be the way to go, but before I commit to it I wanted a second opinion, as this is the first time I've made anything like this!

是否真的需要全实时?从我的角度来看,我会preFER HTTP,因为它已经很好地融入了iOS SDK。它很容易理解,维护和执行以及大量的文档在网络上。因此,也许一个HTTP调查每分钟左右就足够了(这取决于应用程序和用户的数量)。请考虑防火墙呢!交通未知端口可能被拒绝,由于供应商或本地的无线网络的防火墙策略。所以,如果你真的需要实时连接我想你必须使用套接字。

Does it really need to be "full real time"? From my point of view i would prefer http since it is already well integrated into the iOS SDK. Its easy to understand, maintain and implement and plenty of documentation is on the web. So maybe a http poll every minute or so will be enough (depending on the app and the number of users). Please consider firewalls too! Traffic to unknown ports maybe denied due to firewall policies of provider or local wifi. So if you really need realtime connectivity I guess you have to use sockets.