【问题标题】:App Transport Security policy requires the use of a secure connection - IOS 9应用程序传输安全策略需要使用安全连接 - IOS 9
【发布时间】:2015-12-19 03:39:58
【问题描述】:

我在使用 IP 地址连接 API 时遇到问题。 即使我在 plist 中添加了以下代码,它仍然显示如下错误:

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

这是我添加到 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>

【问题讨论】:

    标签: ios connection


    【解决方案1】:

    只需 3 步即可轻松解决问题

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

    【讨论】:

      【解决方案2】:

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

      要配置每个域的例外:

      <?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 文件后如下所示:

      或禁用 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 文件后如下所示:

      【讨论】:

      • 是的,我在 NSAppTransportSecurity 中占有一席之地。但仍然收到相同的错误:无法加载资源,因为应用传输安全策略需要使用安全连接。
      • 这不是真的,因为如果您将 NSAppTransportSecurity 添加到您的主信息 plist 文件中。所有到该域的连接都将允许在非安全模式下运行
      • 我只是把你的代码放到 plist 中。但仍然收到同样的错误
      • 尝试以第二种方式禁用 ATS。并检查 plist 文件是否真的是“目标”->“构建设置”中的 Info.plist 文件设置
      • @voghDev 您可以在图片示例中看到:stackoverflow.com
      猜你喜欢
      • 1970-01-01
      • 2015-12-14
      • 2017-06-10
      • 1970-01-01
      • 2016-06-07
      • 2015-12-15
      • 2016-01-17
      • 2016-08-27
      相关资源
      最近更新 更多