iPhone XML/JSON 请求中的请求超时

发布于 2024-09-08 21:15:02 字数 182 浏览 0 评论 0原文

这是处理请求超时的最佳方法。我正在发送 XML 请求,如果在 10 秒内没有得到响应,我需要停止活动指示器并显示警报消息。

哪种方法最好:

以下 NSTimer - 检查响应的状态

b. NSThread - 这将在后台运行以检查响应

c。通知类(我从未使用过)

谢谢

Which is the best way to handle request-timeout. I am sending XML request and if I didn't get response in 10 sec I need to stop activity indicator and show alert message.

Which approach is best out of following:

a. NSTimer - To check status of response

b. NSThread - This will run in background to check response

c. Notification class (I never used it)

Thanks

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

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

发布评论

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

评论(1

邮友 2024-09-15 21:15:02

如果您使用 NSMutableURLRequest 那么您可以在此给出时间间隔,

例如。

NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];     

所以不需要使用定时器或线程

If you use NSMutableURLRequest then you can give time interval in this

for eg.

NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];     

so no need to use timer or thread

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