SwiftUI프로그래밍

[SwiftUI] Task …finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 “An SSL error has occurred and a secure connection to the server cannot be made.” 해결방법은?

ios 어플을 개발중인데, 공공api 호출하니, 아래와 같은 오류가 발생하였다. ios 어플 개발은 처음이라, 삽질을 제대로 하고 있다.

Task <97F154E2-4D6D-468D-895F-0DFFFB5E6583>.<1> finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://apis.data.go.kr/1160100/service/GetKrxListedInfoService/getItemInfo?serviceKey=BCM...&resultType=json&numOfRows=1000&pageNo=1&basDt=20250508, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <97F154E2-4D6D-468D-895F-0DFFFB5E6583>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <97F154E2-4D6D-468D-895F-0DFFFB5E6583>.<1>"
), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made.,

<1> finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 “An SSL error has occurred and a secure connection to the server cannot be made.”


SSL error has occurred and a secure connection to the server cannot be made 원인

 IOS10부터는 ATS(App Transport Security)가 강화되어 보안이 안전하지 않은 Https 트래픽을 비활성화 되어 호출되지 않는다.


해결방법

Info.plist에서 ATS setting을 추가하여 해결한다.

프로젝트 파일의 Info.plist에서 Information Property List 옆의 +버튼을 눌러 App Transport Security Settings 항목을 추가한다.

  1. Exception Domain – NSIncludesSubdomains 추가, Boolean type, value를 YES 값 설정
  2. Exception Domain – NSExceptionAllowsInsecureHTTPLoads 추가, Boolean type, value를 YES 값 설정
  3. App Transport Security Settings – Allow Arbitrary Loads 의 value 를 Yes로 변경


[reference]

https://leetaek.tistory.com/3

error: Content is protected !!