iOS 9 ... WebView 是否不受阻止不安全 HTTP 主机的应用程序传输安全例外 (ATS) 规则的约束?
iOS 9 ... Are WebView(s) exempt from the App Transport Security Exceptions (ATS) rules that block insecure HTTP hosts?
在 iOS9 中,Apple 将阻止应用程序的不安全 HTTP 连接,除非特定主机已列入白名单。
http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/
WebView 是否出于显而易见的原因免于遵守这些规则,或者我们是否仍希望将浏览器打开的主机列入白名单...包括来自给定页面的所有链接?
我不确定这是我们的责任还是免责。
我已根据 Apple 指南在我的应用程序 .plist 中插入以下内容:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections - with and without SSL (DANGEROUS)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
当我尝试加载我的 webView(至少从 HTTPS 服务器)时,出现以下错误并且它没有加载。
NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)
所以我看起来它们不仅不能豁免,而且即使您正确添加到 .plist 中,它们也不起作用。
SFSafariViewController 可以在没有 NSAppTransportSecurity 密钥的情况下显示 HTTP。
UIWebView 和 WKWebView 需要上述 NSAppTransportSecurity 密钥才能显示 HTTP 页面。
如果您的应用程序(例如第三方网络浏览器)需要加载任意内容,Apple 提供了一种完全禁用 ATS 的方法,但我怀疑您最好谨慎使用此功能:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
这个问题原来是关于iOS9;然而,根据 Apple 的 documentation:
Starting in iOS 10.0 and later, the following subkeys are supported:
- NSAllowsArbitraryLoadsInWebContent
- ...
使用 NSAllowsArbitraryLoadsInWebContent 这样您就不需要将 WebView 可能加载的每个页面都列入白名单。
保留 NSAllowsArbitraryLoads 以保持与 iOS 9 的向后兼容性,并在您的 Xcode 8 项目 Info.plist 中启用新设置:
在 iOS9 中,Apple 将阻止应用程序的不安全 HTTP 连接,除非特定主机已列入白名单。
http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/
WebView 是否出于显而易见的原因免于遵守这些规则,或者我们是否仍希望将浏览器打开的主机列入白名单...包括来自给定页面的所有链接?
我不确定这是我们的责任还是免责。
我已根据 Apple 指南在我的应用程序 .plist 中插入以下内容:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections - with and without SSL (DANGEROUS)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
当我尝试加载我的 webView(至少从 HTTPS 服务器)时,出现以下错误并且它没有加载。
NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)
所以我看起来它们不仅不能豁免,而且即使您正确添加到 .plist 中,它们也不起作用。
SFSafariViewController 可以在没有 NSAppTransportSecurity 密钥的情况下显示 HTTP。
UIWebView 和 WKWebView 需要上述 NSAppTransportSecurity 密钥才能显示 HTTP 页面。
如果您的应用程序(例如第三方网络浏览器)需要加载任意内容,Apple 提供了一种完全禁用 ATS 的方法,但我怀疑您最好谨慎使用此功能:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
这个问题原来是关于iOS9;然而,根据 Apple 的 documentation:
Starting in iOS 10.0 and later, the following subkeys are supported:
- NSAllowsArbitraryLoadsInWebContent
- ...
使用 NSAllowsArbitraryLoadsInWebContent 这样您就不需要将 WebView 可能加载的每个页面都列入白名单。
保留 NSAllowsArbitraryLoads 以保持与 iOS 9 的向后兼容性,并在您的 Xcode 8 项目 Info.plist 中启用新设置: