-
Notifications
You must be signed in to change notification settings - Fork 0
2023 05 21
- URLComponents 이용한 URL 생성
- URL을 통한 API 데이터 수신
- 데이터를 DTO로 변환
App Transport Security has blocked a cleartext HTTP connection toapi.data.go.krsince it is insecure. Use HTTPS instead or add this domain to Exception Domains in your Info.plist.
및 Cannot start load of Task <29C551A3-2071-4BA0-852A-9C653A3D0EE5>.<1> since it does not conform to ATS policy
공공데이터를 받기 위한 URL의 Scheme이 HTTP이기에 연결을 앱 보안상 차단되어 데이터를 받을 수 없는 문제 발생

Allow Arbitrary Loads를 YES로 변경하여 데이터를 수신할 수 있도록 변경
URLComponents로 만들어진 문자열을 URL로 변환과정에서 이미 Encoding이 된 API KEY를 또다시 Encoding이 되면서 달라진 URL로 통신이 안되는 문제가 발생

%2BjVASg%3D%3D
-> %25BjVASg%253D%253D
그렇기 때문에 Encoding을 제거하여서 키를 removingpercentencoding을 사용하여 인코딩을 제거, rfc3986에서 예약된 문자로 =
은 변경이 되지만, +
의경우에는 문자의 조합에서도 사용되어 변환이 되지 않은 거 같아 URLComponents의 percentEncodedQuery에서 percentEncodedQuery?.replacingOccurrences(of: "+", with: "%2B")
해주는 방법으로 API를 받게 되었습니다
더욱 범용성있는 코드를 만들기 위에서는 강제로 변환하는 것은 좋지 않다고 생각하나 예외의 상황이라 판단하여 강제 변환을 했습니다
developer 박재우