webview + swift 5

Hi. I want to make an application on IOS.

Opened the application - loaded a certain site

The code is compiled, but the output is a white screen.

Is there a problem?



//
//  ViewController.swift

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var WebView: UIWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let url = URL(string: "http://www.apple.com")
        WebView.loadRequest(URLRequest(url: url!))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}

Replies

First of all, if you start developing your app since now on, you should not use `UIWebView`, it's deprecated in iOS 12.0 and will be removed at any time in the near future.


But, as for now, `UIWebView` is still available and your code works as expected (I mean Apple's site shown, which is not a white screen) if your correctly setup your storyboard and the URL is the Apple's as shown in your post, tested on Xcode 10.2.1.


Is the URL shown in your post is really the same as you have tried?

Usually, you need to put some ATS settings in your Info.plist to load http contents into webView.

Don't you have something like this in your debug console?

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