这有点奇怪。对于NSURLConnectionDelegate
文档说:
The NSURLConnectionDelegate protocol defines the optional methods implemented by delegates of NSURLConnection objects.
最重要的词有被可选。
然而,NSURLConnection
类引用说:
NSURLConnection’s delegate methods—defined by the NSURLConnectionDelegate protocol—allow an object to receive informational callbacks about the asynchronous load of a URL request. Other delegate methods provide facilities that allow the delegate to customize the process of performing an asynchronous URL load. These delegate methods are called on the thread that started the asynchronous load operation for the associated NSURLConnection object.
这两个似乎自相矛盾。
最后,“网址加载系统编程指南”说:
In order to download the contents of a URL, an application needs to provide a delegate object that, at a minimum, implements the following delegate methods: connection:didReceiveResponse:, connection:didReceiveData:, connection:didFailWithError: and connectionDidFinishLoading:.
这是你所期望的NSURLConnection
什么是没有这些委托方法几乎无用。
看看NSURLConnection
的头文件,看起来有一个NSURLConnectionDataDelegate
协议,它列出了所需的委托方法。但是,它们在标题中标记为@optional
。根据NSURLConnectionDataDelegate
的定义,它必须实现NSURLConnectionDelegate
。
如果你宣布你的委托类实现NSURLConnectionDataDelegate
协议的Xcode会自动完成委托方法。
这一切都让我觉得有点混乱。 Cocoa/Cocoa Touch API通常比这更干净。
我肯定看不到,苹果可以拒绝的应用程序使用这些委托方法为NSURLConnection
确实没有他们的工作。
在粗略估计它不会工作,因为它不具备的iOS库,iOS和OSX是不同的本质,因此API的差异。如果您使用私有方法,则可能违反Apple的使用条款。 – Devraj 2012-07-06 03:14:43
它确实有效。我已经尝试过,你也可以尝试。我希望你不是基于“粗略猜测”而投下的票。 – rahulg 2012-07-06 03:33:26