iOS5 NSURLConnection 메서드는 더 이상 사용되지 않습니다.
네트워크를 통해 데이터를 가져 오기 위해 비동기식 요청을하는 iOS 앱을 작성하려고합니다. 많은 사람들이이를 위해 NSURLConnection 사용을 권장하는 것처럼 보이며 자주 대리자 메소드 connection : didReceiveData :를 언급합니다.
불행히도 저는이 대리자 메서드가 어디에 문서화되어 있는지 평생 알 수 없습니다. 하나의 경우 NSURLConnectionDelegate 에 대한 프로토콜 참조에 없습니다 . NSURLConnection Class Reference에 나열되어 있지만 iOS5부터는 분명히 사용되지 않습니다. 이 문서는 더 이상 사용되지 않는 이유 또는 유사한 기능을 달성하기 위해 개발자가 대신 사용해야하는 것을 설명하지 않습니다.
내가 무엇을 놓치고 있습니까? 내가 읽은 많은 내용은 iOS5 용 NSURLConnection이 크게 변경되었음을 암시하는 것 같습니다. 이러한 변경 사항은 어디에 문서화됩니까? 델리게이트 메서드의 문서가 완전합니까?
감사
헤더 파일을 둘러 보면 메서드가 비공식 프로토콜 (사용되지 않는 Obj-C 패턴) NSURLConnectionDataDelegate
에서 in 이라는 공식 대리자 프로토콜로 옮겨 NSURLConnection.h
졌지만 공개 문서는 없습니다.
나머지 문서는 이전과 같은 방법을 계속 사용하므로 문서에서 누락 된 것 같습니다. 즉, 방법은 (대부분) 아무데도 가지 않고 여러 프로토콜로 재편성되었으며 문서화 팀이 느슨해졌습니다. 위임 객체가 적절한 프로토콜을 따르도록 만들고 헤더 파일의 서명을 사용하여 메서드를 구현하십시오.
NSURLConnection.h에 대한 4.3에서 5.0으로의 변경 로그를 보면 문서는 실제로 엉망입니다.
제거됨
Removed -[NSObject connection:canAuthenticateAgainstProtectionSpace:]
Removed -[NSObject connection:didCancelAuthenticationChallenge:]
Removed -[NSObject connection:didFailWithError:]
Removed -[NSObject connection:didReceiveAuthenticationChallenge:]
Removed -[NSObject connection:didReceiveData:]
Removed -[NSObject connection:didReceiveResponse:]
Removed -[NSObject connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:]
Removed -[NSObject connection:needNewBodyStream:]
Removed -[NSObject connection:willCacheResponse:]
Removed -[NSObject connection:willSendRequest:redirectResponse:]
Removed -[NSObject connectionDidFinishLoading:]
Removed -[NSObject connectionShouldUseCredentialStorage:]
Removed NSObject(NSURLConnectionDelegate)
추가됨
Added -[NSURLConnection currentRequest]
Added -[NSURLConnection originalRequest]
Added +[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
Added -[NSURLConnection setDelegateQueue:]
Added NSURLConnectionDataDelegate
Added -[NSURLConnectionDataDelegate connection:didReceiveData:]
Added -[NSURLConnectionDataDelegate connection:didReceiveResponse:]
Added -[NSURLConnectionDataDelegate connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:]
Added -[NSURLConnectionDataDelegate connection:needNewBodyStream:]
Added -[NSURLConnectionDataDelegate connection:willCacheResponse:]
Added -[NSURLConnectionDataDelegate connection:willSendRequest:redirectResponse:]
Added -[NSURLConnectionDataDelegate connectionDidFinishLoading:]
Added NSURLConnectionDelegate
Added -[NSURLConnectionDelegate connection:canAuthenticateAgainstProtectionSpace:]
Added -[NSURLConnectionDelegate connection:didCancelAuthenticationChallenge:]
Added -[NSURLConnectionDelegate connection:didFailWithError:]
Added -[NSURLConnectionDelegate connection:didReceiveAuthenticationChallenge:]
Added -[NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge:]
Added -[NSURLConnectionDelegate connectionShouldUseCredentialStorage:]
Added NSURLConnectionDownloadDelegate
Added -[NSURLConnectionDownloadDelegate connection:didWriteData:totalBytesWritten:expectedTotalBytes:]
Added -[NSURLConnectionDownloadDelegate connectionDidFinishDownloading:destinationURL:]
Added -[NSURLConnectionDownloadDelegate connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytes:]
Added NSURLConnection(NSURLConnectionQueuedLoading)
따라서 이러한 기능은 실제로 여전히 존재하는 것 같습니다. @interface 선언에 프로토콜을 추가하기 만하면됩니다.
새로운 NSURLConnectionDownloadDelegate를 시도했지만 이러한 메서드가 대리자에 있으면 NSURLConnectionDataDelegate 메서드가 호출되지 않는다는 경고를받습니다.
I also had issue opening the destinationURL, iOS kept telling me the file did not exist although the documentation indicates the file is guaranteed to exist during the method call.
The documentation is a @$@#$ mess. That's the real story.
The Documentation on NSURLConnection
, as written, leaves you high and dry.
The first part of the documentation tells you to use various methods in the NSURLConnection
protocol (like connection:didReceiveData:
) to handle incoming data. If you click on any of those methods in the overview, it leads you to a list of DEPRECATED METHODS!)
The real story that I've been able to piece together is that most of the methods formerly in NSURLConnectionProtocol
have been moved to a new protocol called NSURLConnectionDataProtocol
. Unfortunately, that new protocol is either not documented, or it's not indexed, so you can't find it. Which amounts to the same thing.)
In other interesting news, there is apparently a new protocol called NSURLConnectionDownloadDelegate
. It sounds like NSURLConnection
for iOS is adding some of the functionality that is available in NSURLDownload
in MacOS. The NSURLConnectionDownloadDelegate
protocol IS documented.
You would think deprecating those methods from NSURLConnection would warrant some kind of explainer, but I have not yet found one. The best I could do so far is from Apple's URL Loading System Programming Guide:
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:
andconnectionDidFinishLoading:
which implies an informal protocol.
참고URL : https://stackoverflow.com/questions/7862316/ios5-nsurlconnection-methods-deprecated
'Nice programing' 카테고리의 다른 글
SQL Server 2008 Developer를 설치할 때 사용할 계정 (0) | 2020.11.18 |
---|---|
멤버 변수 대 조각의 setArguments (0) | 2020.11.18 |
R로 압축하거나 열거 하시겠습니까? (0) | 2020.11.18 |
캐싱이란 무엇입니까? (0) | 2020.11.18 |
다중 처리의 로그 출력. 프로세스 (0) | 2020.11.18 |