定期从 NSURLConnection 接收数据

发布于 2024-09-30 09:21:03 字数 258 浏览 0 评论 0原文

我正在使用 NSURLConnection 接收一些数据(JSON 格式)并在 connectionDidFinishLoading 方法中执行一些工作(例如将数据写入标签)。我想要的是,这应该发生,例如每两秒发生一次。即,接收数据>接收数据。将数据写入标签>等待2秒>接收数据... 换句话说,我想每两秒更新一次数据。当然,这应该在后台完成,以免阻止应用程序。

应该做什么?我是否需要 runloop、nstimer 或 NSOperation?我应该如何使用它们?

I am using NSURLConnection to receive some data (in JSON) and do some work (e.g. write data to a label) in connectionDidFinishLoading method. What I want is, this should happen e.g. every two seconds. That is, ReceiveData > WriteDataToLabel > Wait 2 seconds > ReceiveData ...
In other words, I want to update my data every two seconds. Of course, this should be done in background not to block app.

What should be done? Do I need runloop, nstimer or NSOperation and how should I use them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风流物 2024-10-07 09:21:03

问题是“应该做什么?”

我相信答案是“不是这个”

不推荐从每台拥有您的设备的设备每两秒 ping 一次服务器。应用程序运行

Question is "What should be done ?"

I believe the answer is "Not This"

Not a recommended approach to be pinging the server every two seconds from every device that has your application running

简单气质女生网名 2024-10-07 09:21:03

好吧,我了解到您可以使用 NSTimer 来做到这一点。这很容易。

查看此链接:https://developer.apple .com/library/ios/#documentation/Cocoa/Conceptual/Timers/Timers.html

(你也可以考虑@Aaron的话)

Okey, I learned that you can do this using NSTimer. It is pretty easy.

Check out this link: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Timers/Timers.html

(You may also consider @Aaron's words)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文