問題描述
我正在嘗試編寫一個 iOS 應用程序,它發出異步請求以通過網絡獲取數據.似乎很多人為此推薦使用 NSURLConnection,并且經常提到委托方法 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:.
不幸的是,我終生無法找到此委托方法的文檔記錄.一方面,它不在 NSURLConnectionDelegate 的協議參考.它列在 NSURLConnection 類參考,但顯然在 iOS5 中已被棄用.該文檔沒有解釋為什么它被棄用,或者開發人員應該使用什么來實現類似的功能.
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.
我錯過了什么?我讀過的很多內容似乎暗示了對 iOS5 的 NSURLConnection 進行了重大更改.這些更改記錄在哪里?委托方法的文檔是否完整?
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?
謝謝
推薦答案
搜索頭文件告訴我,這些方法已從非正式協議(這是一種已棄用的 Obj-C 模式)轉移到名為 NSURLConnectionDataDelegate
位于 NSURLConnection.h
中,但沒有公共文檔.
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.
文檔的其余部分繼續使用以前的方法,所以我猜這是文檔中的一個遺漏.IE.這些方法(大部分)不會去任何地方,它們只是被改組為幾個協議,文檔團隊一直在懈怠.嘗試使您的委托對象符合適當的協議,并使用頭文件中的簽名實現方法.
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.
這篇關于不推薦使用 iOS5 NSURLConnection 方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!