Getting Blank Screen in WebView using Swift

北慕城南 提交于 2019-12-25 05:05:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!