Search code examples
iosswiftuiwebview

UIWebView giving only a white screen - Xcode 7


Since the recent update to Xcode 7, I have found that my webView will no longer load, it will only show a white screen.

I have searched for a solution, to no avail.

I have coded the webView connection as follows:

class ViewController: UIViewController {

@IBOutlet weak var webviewInstance: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Connect UIWebView to the ordering page

    let url = NSURL (string: "http://www.google.com");
    let requestObj = NSURLRequest(URL: url!);
    webviewInstance.loadRequest(requestObj);
}

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


}

I would greatly appreciate any help with this.


Solution

  • You have to check the app plist file and add the AppTransportSecurity. Open your plist file and add this. Search for AppTransportSecurity

    <key>NSAppTransportSecurity</key>
    <dict>
      <!--Include to allow all connections (DANGER)-->
      <key>NSAllowsArbitraryLoads</key>
          <true/>
    </dict>
    

    If you don't add the ATS in your PLIST your link are ignored/blocked. I hope this can help you