IOS

[iOS] URLSessionTask failed with error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection. HTTP접근 허용

clamp 2023. 4. 6. 13:14

Alamofire를 사용해 통신을 하다가  다음과 같은 에러가 발생했다.

URLSessionTask failed with error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

 

APP Transport Security(ATS):

HTTP에서 보안이 향상된 버전이 HTTPS이며 대부분의 웹이 HTTPS를 사용하고 있지만 그렇지 않은 서비스도 있다.

iOS9 이후로 APP Transport Security(ATS)를 이용하여 HTTP접속을 통한 접속을 기본적으로 차단한다.

 

 

내가 접근한 API

"http://openapi.seoul.go.kr:8088...."

 

http를 사용하고 있기 때문에 이런 에러가 발생한것.

 

해결방법.

1. info.plist 파일을 우클릭해 Source Code로 연다.

 

2. 아래 소스코드를 첫 번째 <dict>아래 붙혀넣는다.

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

 

 

붙혀 넣으면 plist의 Propertylist에선 추가되지 않던 항목들이 생겨난다.