问题
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.
}
}
回答1:
You have to set the NSAllowsArbitraryLoads
key to YES
under NSAppTransportSecurity
dictionary in your .plist file.
Like this Image:
回答2:
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
回答3:
webView.loadRequest(request as URLRequest)
try this it might help..
来源:https://stackoverflow.com/questions/43913924/getting-blank-screen-in-webview-using-swift