0

My class:

import UIKit
import WebKit
import PKHUD

class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

    @IBOutlet weak var webView: WKWebView!

    override func viewDidLoad() {
        webView.navigationDelegate = self
        webView.load(URLRequest(url: URL(string: "https://www.google.com.br")!))
    }

    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        PKHUD.sharedHUD.contentView = PKHUDProgressView()
        PKHUD.sharedHUD.show()
    }

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        PKHUD.sharedHUD.contentView = PKHUDProgressView()
        PKHUD.sharedHUD.hide()
    }
}

But websites with only 'http' don't works. Is that possible? Specs: iOs: 11.4 Swift language Xcode 9.4.1

novaeslucas
  • 19
  • 2
  • 3

4 Answers4

3

To support also an unsecure connection do this:

1.Open the info.plist file

2.Add the Key called App Transport Security Settings as Dictionary (Dictionary should be the default type)

3.Add the Subkey called Allow Arbitrary Loads as Boolean (Boolean should be the default type). Set it to YES

enter image description here

enter image description here

Amit gupta
  • 553
  • 3
  • 10
3

This is happening because transport security has blocked unsecure HTTP connection. to allow HTTP, open your Info.plist as source code and add the following.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>yourDomain.com</key> // here put your domain or ip addres
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>
Ajay saini
  • 2,352
  • 1
  • 11
  • 25
2

You need to set Allow Arbitrary Loads value to true from plist.

enter image description here

iVarun
  • 6,496
  • 2
  • 26
  • 34
0

Yes but for this you need to add in your info.plist

NSAppTransportSecurity <- Type Dictionary

NSAllowsArbitraryLoads <- Type Boolean Value YES

Apple Documents

Community
  • 1
  • 1