iPhone 库存应用程序的建筑草图
我目前正在尝试构建一个(简化的)股票应用程序(就像 iPhone 上内置的应用程序)。我设置了一个带有 REST 接口的简单服务器,我的应用程序可以与它进行通信。
然而,我正在努力寻找在 iPhone 上构建这种(流数据消费者)客户端的正确/最佳方法。
目前我最好的选择是使用计时器定期从服务器拉取 xml 有效负载(连接是异步的,但 xml 解析不是,因此接口有时会被阻塞。我对线程编程有点害羞,因为我学到了一些在其他平台上的教训)。
我读到了有关 websockets 的内容,但我不清楚 iPhone 是否以及如何支持它们。
你会怎么做?
任何提示将不胜感激,谢谢。
I am currently trying to build a (simplified) stock app (like the one built-in on the iphone). I setup a simple server with a REST-interface which my app can communicate with.
However I am struggling to find the right/best way to build this kind of (streaming data consumer) client on the iphone.
My best bet at the moment is to use a timer to regularly pull the xml payload from the server (the connection is async but the xml parsing is not therefor the interface is blocked sometimes. I am a bit shy of thread programming since I learned some lessons the hard way on other platforms).
I read about websockets but it is not clear for me if and how they are supported on the iphone.
How would you do it?
Any hint would be appreciated, Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
websockets 不会帮助你——这是一种服务器端技术,可以使类似套接字的接口通过 HTTP 工作。
如果你不想阻塞GUI,你需要使用另一个线程。您害怕这样做是正确的,因此在两个线程之间尽可能少地共享(最好什么也不共享)。使用消息传递机制将信息从后台线程获取到UI线程。
看看 ActorKit: http://landonf.bikemonkey.org/code/iphone /ActorKit_Async_Messaging.20081203.html
websockets aren't going to help you -- that's a server-side technology to make a socket-like interface work over HTTP.
If you don't want to block the GUI, you need to use another thread. You are right to be scared of doing this, so share as little as possible (preferably nothing) between the two threads. Use a message passing mechanism to get information from the background thread to the UI thread.
Take a look at ActorKit: http://landonf.bikemonkey.org/code/iphone/ActorKit_Async_Messaging.20081203.html
看看这个问题。
它讨论了异步连接与同步连接。您将需要使用异步调用来获取数据,这样就不会锁定您的 UI。您可以将其与轮询计时器结合使用,从服务器获取数据。
您可以在苹果文档中找到有关 NSURLConnection 的更多信息 这里
Take a look at this question.
It talks about asynchronous vs synchronous connections. You will want to use an asynchronous call to get your data so you don't lock up your UI. You could use that in conjunction with a polling timer to get your data from the server.
You can find more info about the NSURLConnection in apple's documentation here