保持持久套接字对 IOS 应用程序的服务器打开的最佳实践
我的应用程序需要与服务器建立开放连接以进行实时更新。我需要能够浏览多个视图,在此期间我可以异步发送和接收数据。目标是让应用程序自动实时更新数据。
我想做的是有一个继承自 NSObject 的单独套接字管理器类,该类具有 CocoaAsyncSocket 的委托函数以及一些辅助函数,然后当持久套接字发生问题时,会在类内进行处理并发出通知根据您当前所在的视图而产生不同的效果。
这样做的首选方式是什么?为此套接字管理器设置协议并使每个 UI 视图都是委托*?或者让套接字管理器位于后台线程并发送通知会更好吗?相对于电池寿命,是否有更好的选择?
*或多或少类似于 http: //www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
My app requires an open connection with a server for real-time updates. I need to be able to navigate through a number of views, during which I can send and receive data asynchronously. The goal is to have the app automatically update data in real time.
What I'd like to do is have a separate socket manager class inheriting from NSObject that has the delegate functions of CocoaAsyncSocket plus some helper functions, and then when stuff happens with the persistent socket, that is handled within the class and it sends out notifications that have different effects depending on which view you are currently on.
What is the preferred way of doing this? Set up a protocol for this socket manager and have every UI view be a delegate*? Or would I be better off having the socket manager sit in a background thread and send notifications? Is there a preferred choice vis a vis battery life?
*More or less like http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论