Swift UIWebView not loading http sites(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 网站
基础教程推荐
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
