SwiftUI HTTP 접근 허용하기 : App Transport Security policy requires the use of a secure connection.
by Steady OnHTTP 서버 혹은 open API에 접근할 때 뜨는 오류
// Fatal error 메세지 Thread 2: Fatal error: Unable to parse data : 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="문제가 되는 url주소", NSErrorFailingURLKey="문제가 되는 url주소"
// 터미널에 쓰는 메세지 Cannot start load of Task <3B8EBA29-98AB-48D9-A801-40A3B305F588>.<1> since it does not conform to ATS policy
원인
- App Transport Security policy requires the use of a secure connection.
- ATS policy란?
- iOS9버전부터 적용된 보안 정책으로 개인정보보호 기능
- HTTP는 안전하지 않다고 여겨서 접근을 막음
해결방법
- 네비게이터에서 최상단에 위치한 프로젝트 클릭(이런저런 설정을 모아둔 곳)
- Targets → Info 탭 클릭
- Bundle name에 커서를 갖다대면 나오는 +버튼 클릭
- App Transport Security Settings 를 찾아 추가하고 그 줄에서 + 버튼 한번 더 클릭
- Allow Arbitary Loads 를 찾아 추가 하고 오른쪽에서 No → Yes로 변경
주의사항
- 결국 보안에 관련된 것이므로 검증된게 아니라면 이 설정을 건드리지 않는것이 좋음
블로그의 정보
Roen의 iOS 개발로그
Steady On