Swift UIWebView 不加载 http 网站

Swift UIWebView not loading http sites(Swift UIWebView 不加载 http 网站)

本文介绍了Swift UIWebView 不加载 http 网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 Web 视图控制器,它加载 https 站点(例如:、)但不加载 http、非 ssl 安全站点(例如: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?

推荐答案

这是由于 Apple 在 WWDC 2015 上引入的新协议 App Transport Security.它不允许任何非 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 文件并选择 Open As -> Source File 并添加以下代码:

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 请求.

希望对您有所帮助,朱利安.

Hope that helps, Julian.

这篇关于Swift UIWebView 不加载 http 网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Swift UIWebView 不加载 http 网站

基础教程推荐