NSURLConnection - 如何等待完成 [英] NSURLConnection - how to wait for completion

查看:86
本文介绍了NSURLConnection - 如何等待完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的iPhone应用程序代码目前使用NSURLConnection sendSynchronousRequest,除非我们需要更多的连接进度和缓存的可见性,所以我们转到异步NSURLConnection。

Our iPhone app code currently uses NSURLConnection sendSynchronousRequest and that works fine except we need more visibility into the connection progress and caching so we're moving to an async NSURLConnection.

等待异步代码完成的最简单的方法是什么?包装在NSOperation / NSOperationQueue,performSelector ...或什么?

What's the simplest way to wait for the async code to complete? Wrap it in a NSOperation/NSOperationQueue, performSelector..., or what?

谢谢。

推荐答案

我回答这个问题,以防任何人在未来碰到这个问题。 Apple的URLCache示例代码是一个很好的例子。您可以在以下网址找到它:

I'm answering this in case anyone else bumps into the issue in the future. Apple's URLCache sample code is a fine example of how this is done. You can find it at:

  • iOS Developer Library - URLCache

上面的评论 - 不要阻止/等待 - 通知。

As John points out in the comment above - don't block/wait - notify.

这篇关于NSURLConnection - 如何等待完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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