2013-02-23 37 views
1

本地SDK中是否提供了取消URL请求的方法? 我知道这个方法:取消NSURLRequest

[connection cancel] 

但我想知道,如果我们能取消的请求。我只想使用本机SDK,我不允许使用第三方库。 也有一种方法来跟踪本地库的下载进度?

+0

对于第二部分,检查[NSURLConnectionDownloadDelegate协议参考](http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSURLConnectionDownloadDelegate_Protocol/NSURLConnectionDownloadDelegate/NSURLConnectionDownloadDelegate.html) – iDev 2013-02-23 01:18:03

+0

@ ACB谢谢。这绝对有助于我的第二部分。 – user2070420 2013-02-23 01:19:28

+0

对于第一部分,[连接取消]是什么问题? – iDev 2013-02-23 01:24:17

回答

1

对于第一部分,您需要调用NSURLConnection上的取消作为[connection cancel]

NSURLRequest documentation:每NSURLConnection documentation

An NSURLConnection object provides support to perform the loading of a URL request. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request.

所以您要取消一个URL连接,而不是一个URL请求

NSURLRequest encapsulates two basic data elements of a load request: the URL to load, and the policy to use when consulting the URL content cache made available by the implementation.

而作为。

对于第二部分,请检查NSURLConnectionDownloadDelegate Protocol Reference。它具有以下用于此目的的委托方法。

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