具有来自服务器的实时更新的 iOS 应用程序:套接字(使用流)或 Apple 推送通知服务? [英] iOS app with real-time updates from server: Socket (using streams) or Apple Push Notification service?

查看:29
本文介绍了具有来自服务器的实时更新的 iOS 应用程序:套接字(使用流)或 Apple 推送通知服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个 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:


创建从应用程序到服务器的套接字,并通过流交换信息.

  • 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 与服务器进行通信,并且通过应用程序的每个请求让服务器知道他们正在查看什么.如果有新内容可供用户使用,请发送 Apple 推送通知(没有可见警报),让应用知道它可以下载新内容.

  • 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!

推荐答案

真的需要全实时"吗?从我的角度来看,我更喜欢 http,因为它已经很好地集成到了 iOS SDK 中.它易于理解、维护和实施,网上有大量文档.因此,也许每分钟左右进行一次 http 轮询就足够了(取决于应用程序和用户数量).也请考虑防火墙!由于提供商或本地 wifi 的防火墙策略,到未知端口的流量可能会被拒绝.因此,如果您真的需要实时连接,我想您必须使用套接字.

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.

这篇关于具有来自服务器的实时更新的 iOS 应用程序:套接字(使用流)或 Apple 推送通知服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆