NSURLConnection methods no more available in IOS5

前端 未结 4 1965
萌比男神i
萌比男神i 2020-12-12 21:42

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

4条回答
  •  死守一世寂寞
    2020-12-12 22:09

    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:

    Furthermore, there are two subprotocols that conform to NSURLConnectionDelegate:

    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:
    • connection:didReceiveData:
    • connection:needNewBodyStream:
    • connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:
    • connection:willCacheResponse:
    • connectionDidFinishLoading:

    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:

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

    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.

提交回复
热议问题