[Xamarin] iOS Url API 호출 시 오류(System.Net.WebException, NSErrorException)
Xamarin.iOS 개발 시 Web API를 이용할 때 아래와 같은 오류가 발생 시 조치 방법
System.Net.WebException
Connection failed: 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={NSUnderlyingError=0x7fada0f31880 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=MyServiceURL, NSErrorFailingURLKey=MyServiceURL, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}
iOS 폴더에 있는 Info.plist 파일을 텍스트 편집기(vsc, Notepad++ 등등...)로 열어서 아래 설정을 입력해줍니다 .
<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
</dict> 
만약 특정 도메인만 연결하도록 하기 위해서는 아래와 같이 설정합니다.
<key>NSAppTransportSecurity</key> 
    <dict> 
    <key>NSExceptionDomains</key> 
        <dict> 
        <!--Include to allow domains--> 
        <key>yourdomain.com</key> 
            <dict> 
            <!--Include to allow subdomains--> 
            <key>NSIncludesSubdomains</key> 
            <true/> 
            <!--Include to allow HTTP requests--> 
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
            <true/> 
            <!--Include to specify minimum TLS version--> 
            <key>NSTemporaryExceptionMinimumTLSVersion</key> 
            <string>TLSv1.1</string> 
        </dict> 
    </dict> 
</dict>