我正在尝试使用https:// URL将页面加载到iOS9上的UIWebView中.加载的页面包括来自不安全服务器的CSS和图像.
例如,页面加载:HTTPS://www.example.com/包括的样式表的http://www.example.com/style.css和图像的http://www.example.com/image.jpg
如果通过不安全连接(常规http)加载原始页面,一切正常.通过HTTPS和HTTP,一切都可以在iOS8上运行.
我没有设定NSAppTransportSecurity到NSAllowsArbitraryLoads应用plist文件:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
虽然通过HTTPS加载页面时,图像加载正常,但CSS文件不加载.似乎UIWebView阻止从安全页面加载不安全的资源.
是否有任何UIWebView设置允许通过不安全的连接加载CSS?
我的代码:
if let url = NSURL(string: "www.google.com") {
let safariViewController = SFSafariViewController(URL: url)
safariViewController.view.tintColor = UIColor.primaryOrangeColor()
presentViewController(safariViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
这只在初始化时崩溃,只有异常:
指定的URL具有不受支持的方案.仅支持HTTP和HTTPS URL
当我使用时url = NSURL(string: "http://www.google.com"),一切都很好.我实际上是从API加载URL,因此,我无法确定它们是否会带有前缀http(s)://.
如何解决这个问题?我应该检查并http://始终加前缀,还是有解决方法?