HTTP Xcode error

A mas de unos no has pasado este error, por que olvidamos simplemente agregar una excepcion a nuestro projecto sobre conexiones «No seguras», aunque es una buena practica en algun momento necesitamos hacer excepciones y habilitar estos dominios como excepciones.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."
"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."
"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."

 

Para simplemente permitir cualquier conexión HTTP desde nuestro proyecto Xcode simplemente tendremos que agregar esto a nuestro archivo «info.plist»

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
NSAppTransportSecurity Dictionary
NSAllowsArbitraryLoads true
NSAppTransportSecurity Dictionary NSAllowsArbitraryLoads true
NSAppTransportSecurity Dictionary
    NSAllowsArbitraryLoads true
NSAllowsArbitraryLoads
NSAppTransportSecurity

Algo que podremos hacer tambien, es colocar excepciones por dominios, digamos que necesitamos hacer llamadas HTTP a un solo dominio en particular.

De esta forma esta agregando solo llamadas HTTP al dominio google.com y sus subdominios:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>google.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <false/> <key>NSExceptionDomains</key> <dict> <key>google.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <false/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>google.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>
NSExceptionDomains

Referencias

https://developer.apple.com/documentation/bundleresources/information_property_list/nsapptransportsecurity