Getting Blank Screen in WebView using Swift

2019-09-14 23:57发布

I am making a simple webview using Swift 3. But after run am getting only the blank screen.

It is not opening the link which I put in url request.

import UIKit

class ViewController: UIViewController {

@IBOutlet var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    let url = URL (string: "http://www.google.net");
    let request = URLRequest(url: url!);
    webView.loadRequest(request);
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

3条回答
聊天终结者
2楼-- · 2019-09-15 00:24
webView.loadRequest(request as URLRequest)

try this it might help..

查看更多
\"骚年 ilove
3楼-- · 2019-09-15 00:35

write this code in info.plist

 <key>NSAppTransportSecurity</key>
 <dict>
 <key>NSAllowsArbitraryLoads</key>
 <true/>
 </dict>

and write this code in viewdid load

webView.opaque = false
webView.backgroundColor = UIColor.clear
查看更多
Animai°情兽
4楼-- · 2019-09-15 00:40

You have to set the NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your .plist file.

Like this Image:

enter image description here

查看更多
登录 后发表回答