2

My WebView is not loading just blank white here is my code

//
//  SecondViewController.swift
//  Bachelmatt Garage
//
//  Created by Thilo Jaeggi on 24.05.17.
//  Copyright © 2017 Thilo Jaeggi. All rights reserved.
//

import UIKit

class SecondViewController: UIViewController {
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let url = URL (string: "http://www.sourcefreeze.com");
    let request = URLRequest(url: url!);
    webView.loadRequest(request);
}


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


}

I already asked the same question a year ago and heard that i somehow need to enable a "security setting" in Xcode is this the same case here? Thanks in advance.

Zarkex
  • 51
  • 7

3 Answers3

1

Please add the following line in your info.plist(open as source code) file

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

For more info please check this Transport security has blocked a cleartext HTTP

Thanks

Bala AP
  • 37
  • 5
1

Open your info.plist as SourceCode and add

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

Then do as mentioned below:

override func viewDidLoad() {
    super.viewDidLoad()
webView.loadRequest(URLRequest(url: URL(string: "http://www.sourcefreeze.com")!))
}
Vamshi Krishna
  • 979
  • 9
  • 19
1

Well It is working perfectly: See the below code:

import UIKit
import SVProgressHUD

class ConditionsViewController: UIViewController, UIWebViewDelegate {

    @IBOutlet weak var webVw: UIWebView!


    override func viewDidLoad() {
        super.viewDidLoad()


        SVProgressHUD.show(withStatus: "Loading")

        webVw.delegate = self

        let url = URL (string: "http://www.sourcefreeze.com");
        let request = URLRequest(url: url!);
        webVw.loadRequest(request);
    }

    func webViewDidFinishLoad(_ webView: UIWebView) {

        SVProgressHUD.dismiss()
    }

enter image description here enter image description here

Edited

import UIKit
   // import SVProgressHUD

    class ConditionsViewController: UIViewController, UIWebViewDelegate {

        @IBOutlet weak var webVw: UIWebView!


        override func viewDidLoad() {
            super.viewDidLoad()


            SVProgressHUD.show(withStatus: "Loading")

            webVw.delegate = self

            let url = URL (string: "http://www.sourcefreeze.com");
            let request = URLRequest(url: url!);
            webVw.loadRequest(request);
        }

        func webViewDidFinishLoad(_ webView: UIWebView) {

            //SVProgressHUD.dismiss()

            print("Loaded")

// Here it will print 2-3 sec later, in that mean time your page will load in your view controller
        }

Mainly I have added UIWebViewDelegate and its delegate method webViewDidFinishLoad . well try it, it will work definitely .

Abhishek Mitra
  • 3,335
  • 4
  • 25
  • 46