問(wèn)題描述
我正在嘗試編寫一個(gè) iOS 應(yīng)用程序,它發(fā)出異步請(qǐng)求以通過(guò)網(wǎng)絡(luò)獲取數(shù)據(jù).似乎很多人為此推薦使用 NSURLConnection,并且經(jīng)常提到委托方法 connection:didReceiveData:.
I'm trying to write an iOS app that makes asynchronous requests to get data over the network. It seems like a lot of people recommend using NSURLConnection for this, and frequently mention the delegate method connection:didReceiveData:.
不幸的是,我終生無(wú)法找到此委托方法的文檔記錄.一方面,它不在 NSURLConnectionDelegate 的協(xié)議參考.它列在 NSURLConnection 類參考,但顯然在 iOS5 中已被棄用.該文檔沒(méi)有解釋為什么它被棄用,或者開(kāi)發(fā)人員應(yīng)該使用什么來(lái)實(shí)現(xiàn)類似的功能.
Unfortunately, I cannot for the life of me find out where this delegate method is documented. For one, it is not in the protocol reference for NSURLConnectionDelegate. It is listed in the NSURLConnection Class Reference, but has apparently been deprecated as of iOS5. The documentation does not explain why it was deprecated, or what developers should use instead to achieve similar functionality.
我錯(cuò)過(guò)了什么?我讀過(guò)的很多內(nèi)容似乎暗示了對(duì) iOS5 的 NSURLConnection 進(jìn)行了重大更改.這些更改記錄在哪里?委托方法的文檔是否完整?
What am I missing? A lot of what I've read seems to imply that big changes were made to NSURLConnection for iOS5. Where are these changes documented? Is the documentation of delegate methods complete?
謝謝
推薦答案
搜索頭文件告訴我,這些方法已從非正式協(xié)議(這是一種已棄用的 Obj-C 模式)轉(zhuǎn)移到名為 NSURLConnectionDataDelegate
位于 NSURLConnection.h
中,但沒(méi)有公共文檔.
Fishing around the header files tells me that the methods were moved from an informal protocol (which is a deprecated Obj-C pattern) into a formal delegate protocol called NSURLConnectionDataDelegate
that's in NSURLConnection.h
, but doesn't have a public documentation.
文檔的其余部分繼續(xù)使用以前的方法,所以我猜這是文檔中的一個(gè)遺漏.IE.這些方法(大部分)不會(huì)去任何地方,它們只是被改組為幾個(gè)協(xié)議,文檔團(tuán)隊(duì)一直在懈怠.嘗試使您的委托對(duì)象符合適當(dāng)?shù)膮f(xié)議,并使用頭文件中的簽名實(shí)現(xiàn)方法.
The rest of the documentation keeps using the methods as before, so my guess is this is an omission in the documentation. I.e. the methods (mostly) aren't going anywhere, they were just reshuffled into several protocols and the documentation team has been slacking off. Try making your delegate object conform to the appropriate protocol, and implement the methods with the signatures from the header file.
這篇關(guān)于不推薦使用 iOS5 NSURLConnection 方法的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!