The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

前端 未结 21 1718
醉酒成梦
醉酒成梦 2020-11-22 11:37

I am facing the Problem when I have updated my Xcode to 7.0 or iOS 9.0. Somehow it started giving me the Titled error

\"The resource could not be load

相关标签:
21条回答
  • 2020-11-22 12:31

    For iOS 10.x and Swift 3.x [below versions are also supported] just add the following lines in 'info.plist'

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    
    0 讨论(0)
  • 2020-11-22 12:34

    Make sure you change the right info.plist file.

    This is the second time I waste time on this issue, because I didn't notice that I'm changing info.plist under MyProjectNameUITests.

    0 讨论(0)
  • 2020-11-22 12:35

    Be aware, using NSAllowsArbitraryLoads = true in the project's info.plist allows all connection to any server to be insecure. If you want to make sure only a specific domain is accessible through an insecure connection, try this:

    Or, as source code:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>domain.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict>
    

    Clean & Build project after editing.

    0 讨论(0)
提交回复
热议问题