IOS5中不再提供NSURLConnection方法 [英] NSURLConnection methods no more available in IOS5

查看:112
本文介绍了IOS5中不再提供NSURLConnection方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 NSURLConnection 类,该类可用于建立与URL的同步或异步连接,然后检索其数据...许多更改都有我已经看到他们引入了一些与身份验证或下载相关的正式协议,但是我没有看到,例如,连接:didReceiveResponse:消息(以前发送给代理并且它不再可用)。如何在收到响应后立即实现异步连接并检索HTTP标头?我确信有一种方法比使用 NSURLConnection 以及连接更好:didReceiveResponse:消息..方法如 stringWithContentsOfURL 是否始终同步加载内容?您在应用程序中使用什么来实现异步下载,避免使用已弃用的方法并对_http响应receive_m等事件做出反应?如果可能,你是否在后台任务中启动同步下载?

I was looking at the NSURLConnection class which could be used to establish a sync or async connection to an URL and then retrieve its data... a lot of changes have been made to this class with IOS 5 and I've seen they introduced some formal protocols related to authentication or download, but I don't see, for example, if the connection:didReceiveResponse: message (that was previously sent to the delegate and that it is no more available) is still available in some protocols.. How do you implement an async connection and retrieve, for example, HTTP headers as soon as the Response is received? I'm sure there is a way better than using NSURLConnection along with the connection:didReceiveResponse: message.. methods like stringWithContentsOfURL do always load content synchronously? What do you use to implement async downloads in your apps avoiding deprecated methods and reacting to events such as _http response received_m etc ? Do you launch synchronous downloads in background tasks, if possible?

推荐答案

NSURLConnectionDelegate 已成为正式协议(它是以前版本中的非正式协议)。在此协议中,声明了以下(非弃用)方法:

NSURLConnectionDelegate has become a formal protocol (it was an informal protocol in previous versions). In this protocol, the following (non-deprecated) methods are declared:


  • connection:didFailWithError:

  • connectionShouldUseCredentialStorage:

  • connection:willSendRequestForAuthenticationChallenge :

  • connection:didFailWithError:
  • connectionShouldUseCredentialStorage:
  • connection:willSendRequestForAuthenticationChallenge:

此外,还有两个符合 NSURLConnectionDelegate

NSURLConnectionDataDelegate 用于将数据加载到内存的委托,并声明以下方法,其中一些我相信你会发现它很熟悉:

NSURLConnectionDataDelegate is used for delegates that load data to memory, and declares the following methods, some of which I’m sure you’ll find familiar:


  • connection:willSendRequest:redirectResponse:

  • connection:didReceiveResponse:

  • 连接:didReceiveData:

  • connection:needNewBodyStream:

  • connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:

  • connection:willCacheR esponse:

  • connectionDidFinishLoading:

  • connection:willSendRequest:redirectResponse:
  • connection:didReceiveResponse:
  • connection:didReceiveData:
  • connection:needNewBodyStream:
  • connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:
  • connection:willCacheResponse:
  • connectionDidFinishLoading:

NSURLConnectionDownloadDelegate 用于将数据直接存储到磁盘文件的委托,并声明以下方法:

NSURLConnectionDownloadDelegate is used for delegates that store data directly to a disk file, and declares the following methods:


  • connection:didWriteData:totalBytesWritten:expectedTotalBytes:

  • connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytes:

  • connectionDidFinishDownloading:destinationURL:

  • connection:didWriteData:totalBytesWritten:expectedTotalBytes:
  • connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytes:
  • connectionDidFinishDownloading:destinationURL:

如您所见,您仍然可以使用以前的代表,可能会进行一些小修改。

As you can see, you can still use your previous delegates, possibly with some minor modifications.

For有关详细信息,请参阅 iOS 4.3至iOS 5.0 API差异文档和NSURLConnection.h in您的本地Xcode安装。发布新的SDK版本时,头文件中的文档比开发人员库中提供的文档更可靠,这并不罕见。后者需要一段时间才能保持最新状态。

For more information, see the iOS 4.3 to iOS 5.0 API Differences document and NSURLConnection.h in your local Xcode installation. When a new SDK version is released, it’s not uncommon for the documentation inside the header files to be more reliable than the documentation available on the developer library. It takes a while for the latter to be up-to-date.

这篇关于IOS5中不再提供NSURLConnection方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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