Search code examples
iosswiftxcodeuiwebview

WebView shows blank white screen part from apple.com


I have added a web view to my app however i keep getting a blank white screen when running on simulator or even device. When i enter apple.com as the website it works perfect but for any other website it just shows a blank white screen. import UIKit

class ViewController: UIViewController {

 @IBOutlet var WebView: UIWebView!

override func viewDidLoad() {
super.viewDidLoad()


var URL = NSURL(string: "http://www.apple.com")

WebView.loadRequest(NSURLRequest(URL: URL!))

}

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


}

Solution

  • Have you added autolayout to your webView? As the image below shows? enter image description here

    Just select your webView and click on Add New Constraints and set your constraints.

    If this is not your issue, check the output window if it blocks requests that are not HTTPS, then you can add this code to your info.plist code.

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

    Update
    You´re getting the white screen because you´re missing the http:// in your URL.