首页 文章

应用程序传输安全策略要求使用安全连接 - IOS 9

提问于
浏览
4

我正在使用IP地址与API连接问题 . 即使我已将以下代码添加到plist,它仍然显示如下错误:

http://xx3.xx.xx8.xx7/xxx/xxx/错误:无法加载资源,因为App Transport Security策略要求使用安全连接 . ”

这是我添加到plist的代码

<key>xx3.xx.xx8.xx7</key>
        <dict>
            <key>NSThirdPartyExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </key>

2 回答

  • 15

    文件Allowing Insecure Connection to a Single Server here . 所以你必须将 NSAppTransportSecurity 添加到你的info.plist文件中,就像流动一样(在源代码中显示Info.plist,在Xcode中右键单击Info.plist "Open As" - > "Source Code")

    To configure a per-domain exception:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <!--others key-->
        <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSExceptionDomains</key>
            <dict>
                <key>insecure-domain1.example.com</key>
                <dict>
                    <key>NSIncludesSubdomains</key>
                    <true/>
                    <key>NSExceptionAllowsInsecureHTTPLoads</key>
                    <true/>
                    <key>NSExceptionRequiresForwardSecrecy</key>
                    <false/>
                    <key>NSExceptionMinimumTLSVersion</key>
                    <string>TLSv1.0</string>
                </dict>
                <key>insecure-domain2.example.com</key>
                <dict>
                    <key>NSIncludesSubdomains</key>
                    <true/>
                    <key>NSExceptionAllowsInsecureHTTPLoads</key>
                    <true/>
                    <key>NSExceptionRequiresForwardSecrecy</key>
                    <false/>
                    <key>NSExceptionMinimumTLSVersion</key>
                    <string>TLSv1.0</string>
                </dict>
            </dict>
        </dict>
        <!--others key-->
    </dict>
    </plist>
    

    编辑Infor.plist文件后如下所示:
    enter image description here

    Or disable ATS:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        ...
        <key>NSAppTransportSecurity</key>
        <dict>
            <!--Include to allow all connections (DANGER)-->
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    </dict>
    </plist>
    

    编辑Infor.plist文件后如下所示:
    enter image description here

  • 2

    Simple & Easiest Solution just in 3 Steps

    enter image description here

    添加以下两个属性并再次运行...快乐编码:-)

    enter image description here

相关问题