我写这段代码:
@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
如果你已经从 storyboard 连接它就不需要这行
self.view.addSubview(webView)
关于ios - swift 2.0 UIWebview 只显示白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796483/