问题描述
我创建了一个Web视图控制器,并加载了https站点(例如:),但未加载不受SSL保护的http(例如, http://bswd.us , http://www.barretthillins.com ).当我确实在其中放置一个hhtp网站时,它确实会加载,但只是一个空白的白色Web视图.我该如何解决?
I created a web view controller and it loads https sites(ex: , ) but not http, non ssl secured sites(ex: http://bswd.us, http://www.barretthillins.com). When i do put a hhtp site in there, it does load but just a blank, white web view. How would i need to fix this?
推荐答案
这归因于App Transport Security,这是Apple在WWDC 2015上引入的新协议.它不允许任何非 HTTPS的连接
.您可以禁用它,但是不建议您这样做,因为它可以保护您的应用程序安全.
This is due to the App Transport Security, a new protocol introduced by Apple at WWDC 2015. It doesn't allow any connections that are not HTTPS
. You can disable it, however it's not recommended as it secures your app.
要禁用它,您必须编辑应用程序的 .plist
.只需右键单击 .plist
文件,然后选择打开方式->源文件,然后添加以下代码:
To disable it you have to edit the App's .plist
. Simply right-click the .plist
file and select Open As -> Source File and add the following code:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
这将允许 HTTP
请求.
希望有帮助,朱利安.
这篇关于Swift UIWebView无法加载http网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!