【问题标题】:Error loading web in UIWebView在 UIWebView 中加载网页时出错
【发布时间】:2015-10-14 01:31:05
【问题描述】:

我正在使用 UIWebView,但无法加载 facebook。我不得不说我使用的是 xcode 7 beta 2 和 iOS 9.0 beta 4。

这是错误:

Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."

【问题讨论】:

标签: ios objective-c xcode app-transport-security


【解决方案1】:

所以,我会回答我自己的问题。正如 CSmith 所回答的,苹果希望我们使用 App Transport Security (ATS)。但是,由于有很多人没有准备好,我会展示避免它的方法。在您的 info.plist 中添加以下内容:

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

相关: iOS 9 ... Are WebView(s) exempt from the App Transport Security Exceptions (ATS) rules that block insecure HTTP hosts?

【讨论】:

    【解决方案2】:

    在 iOS 9(和 OS X 10.11)中,应用程序不应发出不受保护的 HTTP 请求,因此默认情况下它们被禁用。此外,您应该使用具有前向保密性的 TLS 1.2。 RC4 和 SHA-1 证书签名被禁用,RSA 的密钥至少应为 2048 位(EC 为 256 位)。

    如果您真的想使用 http 或安全性较低的 https,您可以在应用的 info.plist 文件中定义例外。

    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
      <key>NSExceptionDomains</key>
      <dict>
        <key>yourserver.com</key>
        <dict>
          <!--Include to allow subdomains-->
          <key>NSIncludesSubdomains</key>
          <true/>
          <!--Include to allow HTTP requests-->
          <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
          <true/>
          <!--Include to specify minimum TLS version-->
          <key>NSTemporaryExceptionMinimumTLSVersion</key>
          <string>TLSv1.1</string>
        </dict>
      </dict>
    </dict>
    

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 1970-01-01
      相关资源
      最近更新 更多