【问题标题】:Cannot load HTTP links in UIWebView in iOS 9无法在 iOS 9 的 UIWebView 中加载 HTTP 链接
【发布时间】:2015-12-17 21:23:52
【问题描述】:

我正在尝试在 UIWebView 中加载 HTTP 链接。这些链接来自我的网站,因此它们是可靠的。我已经搜索了互联网并在这里找到了解决方案:How can I add NSAppTransportSecurity to my info.plist file?

遵循该解决方案后,我的 info.plist 如下所示。:

即使进行了更改,我也无法在 UIWebView 中加载 HTTP 链接。我收到以下错误:

App Transport Security 已阻止明文 HTTP (http://) 资源加载,因为它不安全

是不是我做错了什么?

更新:

在 cmets 中进行 Ramshad 建议的更改后,它仍然无法正常工作。 见下图:

【问题讨论】:

标签: ios uiwebview ios9 xcode7 nsapptransportsecurity


【解决方案1】:

应该这样做,你需要在你的Plist中添加以下记录 Apple Documentation

NSAppTransportSecurity

NSAllowsArbitraryLoads

【讨论】:

    【解决方案2】:

    你可以尝试添加所有的东西,没有“http://”:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>mydomain.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSIncludesSubdomains</key>
                <true/>                
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
    

    【讨论】:

      【解决方案3】:

      试试这个,这应该可以解决你的问题

      【讨论】:

      • 感谢您的回复。请参阅我更新的问题。我已经尝试过了,但它对我不起作用。
      【解决方案4】:

      查看这篇文章:link

      应用传输安全 (ATS) 通常不允许我们的应用连接到 HTTP 服务器,但您可以添加一个特殊例外以允许 UIWebView 和 WKWebView 加载不安全的内容。

      TL;DR

      只需添加到您的.plist 文件:

      <key>NSAppTransportSecurity</key>
      <dict>
          <key>NSAllowsArbitraryLoadsInWebContent</key>
          <true/>
      </dict>
      

      NSAllowsArbitraryLoadsInWebContent 在 iOS 9.0 中可用,所以对你来说应该没问题。

      【讨论】:

        【解决方案5】:

        你试过了吗?

        <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSExceptionDomains</key>
            <dict>
                <key>www.mydomain.com</key>
                <dict>
                    <key>NSIncludesSubdomains</key>
                    <true/>
                    <key>NSExceptionMinimumTLSVersion</key>
                    <string>TLSv1.0</string>
                    <key>NSExceptionRequiresForwardSecrecy</key>
                    <false/>
                    <key>NSExceptionAllowsInsecureHTTPLoads</key>
                    <true/>
                </dict>
            </dict>
        </dict>
        

        【讨论】:

          【解决方案6】:

          我认为您拼错了链接或域。

          我遇到了同样的问题,再次检查123.company.othercompany.com的域后,我将company.com更改为othercompany.com,它开始加载外部网站。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-01-02
            • 1970-01-01
            • 2022-07-27
            • 2015-12-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多