2012-07-06 34 views
4

我正在经历的apple.developer.com网站NSURLConnectionDelegate类引用声明为什么不要求NSURLConnection的委托方法。在那里,我意识到像connectionDidFinishLoading这样的函数不在IOS类中,但在MAC库中。在NSURLConnectionDelegate协议

话又说回来,当我尝试使用这些功能在Xcode的iOS应用程序,自动完成不完成,但功能不正常工作。

任何一个可以请解释如何将这些工作和部署应用程序时,将这一事业的任何问题。 谢谢!

+1

在粗略估计它不会工作,因为它不具备的iOS库,iOS和OSX是不同的本质,因此API的差异。如果您使用私有方法,则可能违反Apple的使用条款。 – Devraj 2012-07-06 03:14:43

+0

它确实有效。我已经尝试过,你也可以尝试。我希望你不是基于“粗略猜测”而投下的票。 – rahulg 2012-07-06 03:33:26

回答

1

请记住,如果你发现在API的不一致,你需要RADAR提交错误报告在暗像素友好的家伙解释它:RADAR or GTFO

4

这有点奇怪。对于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确实没有他们的工作。

+0

同意这一点。这不是唯一的课程。我看到了Apple提供的XML解析器类的类似问题。你可以请这个问题投票,(有人把它投下来),以便它可能进来橙色灯 – rahulg 2012-07-06 03:39:58

+0

如果你看看“NSURLConnectionDataDelegate协议参考”说:“这个协议中的许多方法作为非正式协议的一部分存在先前版本的OS X和iOS“。所以在iOS 5.0之前,connectionDidFinishLoading在非正式协议NSURLConnectionDelegate中,但现在在NSURLConnectionDataDelegate中。添加NSURLConnectionDataDelegate为我工作。 – RandomBits 2012-11-01 19:35:12