iOS 9에서 NSURLSession / NSURLConnection HTTP로드 실패
iOS9에서 기존 앱을 실행하려고했지만을 사용하는 동안 오류가 발생했습니다 AFURLSessionManager
.
__block NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
} else {
}
}];
[task resume];
다음과 같은 오류가 발생합니다.
Error Domain=NSURLErrorDomain Code=-999 "cancelled.
또한 다음과 같은 로그가 표시됩니다.
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824
CFNetwork SSLHandshake failed (-9824)
업데이트 : 솔루션에 여러 업데이트를 추가 했습니다. iOS 9에서 NSURLSession / NSURLConnection HTTP로드에 실패했습니다
발견 된 해결책 :
iOS9에서 ATS는 HTTPS 사용을 포함하여 네트워크 호출 중에 모범 사례를 시행합니다.
ATS는 우발적 인 공개를 방지하고 안전한 기본 동작을 제공하며 쉽게 채택 할 수 있습니다. 새 앱을 만들거나 기존 앱을 업데이트하는지 여부에 관계없이 가능한 한 빨리 ATS를 채택해야합니다. 새로운 앱을 개발하는 경우 HTTPS를 독점적으로 사용해야합니다. 기존 앱이있는 경우 지금 가능한 한 HTTPS를 사용하고 가능한 한 빨리 나머지 앱을 마이그레이션하기위한 계획을 세워야합니다.
베타 1에서는 현재 info.plist에서이를 정의 할 수있는 방법이 없습니다. 해결책은 수동으로 추가하는 것입니다.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
업데이트 1 : iOS9 ATS 지원을 채택 할 준비가 될 때까지 임시 해결 방법입니다.
업데이트 2 : 자세한 내용은 다음 링크를 참조하십시오 : http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/
업데이트 3 : TLS 1.0 만있는 호스트 (YOURHOST.COM)에 연결하려고하는 경우
이것을 앱의 Info.plist에 추가하십시오
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>YOURHOST.COM</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>1.0</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
iOS9에서 SSL을 다루는 방법 , 하나의 솔루션은 다음과 같습니다.
애플이 말하는 것처럼 :
앱의 Info.plist 파일에서 예외 도메인을 지정하지 않으면 데이터를 요청하려는 모든 호스트에 대해 iOS 9 및 OSX 10.11에 TLSv1.2 SSL이 필요합니다.
Info.plist 구성의 구문은 다음과 같습니다.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow insecure HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
응용 프로그램 (예 : 타사 웹 브라우저)이 임의의 호스트에 연결해야하는 경우 다음과 같이 구성 할 수 있습니다.
<key>NSAppTransportSecurity</key>
<dict>
<!--Connect to anything (this is probably BAD)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
이 작업을 수행해야하는 경우 TLSv1.2 및 SSL을 사용하도록 아직 업데이트하지 않은 경우 서버를 업데이트하는 것이 가장 좋습니다. 이는 임시 해결 방법으로 간주되어야합니다.
현재 시험판 문서에서는 이러한 구성 옵션에 대해 특정 방식으로 언급하지 않습니다. 일단 완료되면 관련 문서로 연결되도록 답변을 업데이트하겠습니다.
App Transport Security에 관한 Apple의 기술 노트는 매우 편리합니다 . 문제에 대한보다 안전한 솔루션을 찾는 데 도움이되었습니다.
잘하면 이것은 다른 누군가를 도울 것입니다. 완벽하게 유효한 것으로 보이는 Amazon S3 URL, TLSv12 HTTPS URL에 연결하는 데 문제가있었습니다. 우리는 NSExceptionRequiresForwardSecrecy
S3가 사용하는 또 다른 소수의 암호를 활성화 하기 위해 비활성화 해야했습니다.
우리의 Info.plist
:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>amazonaws.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
Amazon S3 에서이 문제가 발생하면 info.plist에 최상위 태그의 직접 하위 항목으로 붙여 넣으십시오.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>amazonaws.com</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>amazonaws.com.cn</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
자세한 정보는 다음에서 찾을 수 있습니다.
http://docs.aws.amazon.com/mobile/sdkforios/developerguide/ats.html#resolving-the-issue
I found solution from here. And its working for me.
Check this, it may help you.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>myDomain.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
Simply add the following fields in your .plist file
Syntax looks like this:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Update:
As of Xcode 7.1, you don't need to manually enter the NSAppTransportSecurity
Dictionary in the info.plist
.
It will now autocomplete for you, realize it's a dictionary, and then autocomplete the Allows Arbitrary
Loads as well. info.plist screenshot
Solve NSURLConnection Http load failed bug Just Add following Dict in info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
I have solved it with adding some key in info.plist. The steps I followed are:
I Opened my project's info.plist file
Added a Key called NSAppTransportSecurity as a Dictionary.
NSAllowsArbitraryLoads라는 하위 키를 부울로 추가하고 다음 이미지와 같이 해당 값을 YES로 설정합니다. 여기에 이미지 설명을 입력하십시오
프로젝트를 청소하면 지금처럼 모든 것이 제대로 작동합니다.
참조 링크 : https://stackoverflow.com/a/32609970
이 오류가 발생했을 때 저에게 효과적이었습니다.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>example.com</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
</dict>
</dict>
</dict>
RCTHTTPRequestHandler.m 파일에이 함수를 추가 할 수 있습니다.
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler { completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]); }
위에서 언급 한 답변 외에도 URL을 다시 확인하십시오.
당신은 추가해야합니다 App Transport Security Settings
으로 info.plist
하고 추가 Allow Arbitrary Loads
로App Transport Security Settings
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
참고 URL : https://stackoverflow.com/questions/30739473/nsurlsession-nsurlconnection-http-load-failed-on-ios-9
'IT' 카테고리의 다른 글
URL에서 JSON 문자열을 얻는 방법은 무엇입니까? (0) | 2020.06.25 |
---|---|
JSON.stringify 출력을 div로 예쁜 인쇄 방식으로 (0) | 2020.06.25 |
char *의 부분 문자열을 얻는다. (0) | 2020.06.24 |
Mvc의 컨트롤러에서 다른 컨트롤러를 호출하는 방법 (0) | 2020.06.24 |
Java Collections 목록을 복사하는 방법 (0) | 2020.06.24 |