ios - swift 2.0 UIWebview 只显示白页

标签 ios iphone swift uiwebview

我写这段代码:

@IBOutlet weak var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    let url = NSURL (string: "http://google.com");
    let requestObj = NSURLRequest(URL: url!);

    webView.loadRequest(requestObj);
    self.view.addSubview(webView)
}

运行代码,iPhone模拟器只显示白页,没有警告错误

然后我将代码更改为:

let url = NSURL (string: "http://apple.com");

把google换成apple就可以了-模拟器显示apple网站

所以我把另一个网站 url 但它和第一个一样,只是它显示 apple.com

我不知道这段代码有什么问题请帮助我!谢谢:)

最佳答案

你应该得到错误:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

如下图所示查找信息并执行以下步骤:

1.On the last line add the +
2.Enter the name of the group: App Transport Security
3.Right click on the group and select Add Row
4.Enter Allow Arbitrary Loads
5.Set the value on the right to YES

enter image description here

如果你已经从 storyboard 连接它就不需要这行

self.view.addSubview(webView)

关于ios - swift 2.0 UIWebview 只显示白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796483/

相关文章:

ios - 如何将 Unity 集成到 Swift 3 iOS 项目中

ios - 如何按时调用函数?另外如何在 swift 3 中只调用一次?

ios - 更新 : Image is captured but will not display

iphone - 学习 objective-c 更有助于理解计算机体系结构

ios - 多行标签和固定大小图标图像的水平 StackView 问题

swift - 在 Swift 的链式方法中将调用对象作为参数传递

ios - 如何在 UICollectionView 的单元格上使用 TouchDragEnter?

ios - 无法为 iphone 4s、5、5s、6、6s 设置纵向和横向模式的启动图像

iphone - iOS 5 上的应用程序崩溃 - 无法实例化名为 NSLayoutConstraint 的类

ios - 如何使用通知和观察者从另一个 UIViewController 隐藏 UILabel