Trgrit Tjforce
Trgrit Tjforce

Reputation: 103

webKit not loading page

I have been attempting to load a webpage in iOS to no avail. I have used the same code on other view controllers in the project but all it shows for this page is the blank white screen. Here is my code:

import UIKit
import WebKit

class FirstViewController: UIViewController { 
    @IBOutlet weak var webView: WKWebView!

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear( animated )

        let url:URL = URL(string: "http://www.fairburyjeffs.org")!
        let urlRequest:URLRequest = URLRequest(url: url)
        webView.load(urlRequest)
    }

Upvotes: 0

Views: 3544

Answers (2)

Rizwan Ahmed
Rizwan Ahmed

Reputation: 958

You are trying to load an HTTP url (i.e "http://www.fairburyjeffs.org") so make sure that you have set Arbitary Loads to YES in info.plist. If you don't set Arbitary Loads to YES, the http pages won't load.

App transport Security Settings and Allowing Arbitrary loads

Upvotes: 1

Rashed
Rashed

Reputation: 2425

Your code are working fine as you wanted to-

enter image description here The reason i found behind this -

  1. If you try https://www.google.com/ . It will work in one RUN. But when you run it with your url it won't. Why? because the difference of http and https. For more you can read the Apple documentations.

    You just need to do the following steps-

    • Open your Info.plist file of your project. Right click on it and add a row.

enter image description here

And after that just add those two lines in your Info.plist (as it is) -

enter image description here

Upvotes: 3

Related Questions