Weekoding

[Swift] HTTP 접근 허용하기(App Transport Security) 본문

공부 노트(Swift)

[Swift] HTTP 접근 허용하기(App Transport Security)

Weekoding 2022. 7. 26. 19:00

App Transport Security(ATS) :

기존의 HTTP에서 보안이 향상된 버전인 HTTPS의 등장으로, 현재 대부분의 웹들이 HTTPS를 사용하고 있다.

장단점이 존재하는 것이 아니라 상대적으로 보안이 취약하기 떄문에,

iOS 9 이후로는 App Transport Security(ATS)를 이용하여 HTTP를 통한 접속을 기본적으로 차단하고 있다.

 

 

따라서, 이에 대한 설정을 하지 않은 채 http로 request를 시도하면 다음과 같은 에러를 발견하게 된다.

Error Domain=NSURLErrorDomain Code=-1022
"The resource could not be loaded because the App Transport Security policy requires
the use of a secure connection."
UserInfo={NSLocalizedDescription=The resource could not be loaded
because the App Transport Security policy requires the use of a secure connection.,
NSErrorFailingURLStringKey= ....

부득이하게 HTTP로 접속해야할 때가 있는데 길을 막아버리면 어떡하나 !,,,

 

 

 

📌   해결 방법

방법은 간단하다. info.plist의 설정값 하나를 변경 혹은 생성해주면 된다.

App Transport Security Settings → Allow Arbitrary Loads (YES)

App Transport Security Settings 탭이 아예 존재하지 않는다면, + 버튼을 눌러 추가하면 된다.(Allow Arbitrary Loads도 마찬가지)

Allow Arbitrary Loads값이 YES가 되면, 더 이상 HTTP 접속이 차단되지 않는다.

그러나 앞서 상술하였듯 HTTP 자체가 보안 상 취약하니 조심하자!

 

 

 

 

오류 및 지적사항은 댓글로 남겨주시면 감사하겠습니다!

Comments