Luv33preet
Luv33preet

Reputation: 1867

using webkitview in swift ios

I want to load a browser in the app.

Below is the code I am using,

import UIKit
import WebKit

class ViewController: UIViewController {


    @IBOutlet weak var webkitview: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        let url = URL(string: "https://www.vogo.in")
        let request = URLRequest(url: url!)
        webkitview.load(request)
   }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
   }
}

But the simulator shows nothing when it is started. And there is no error also. What am I doing wrong?

Upvotes: 1

Views: 986

Answers (1)

Taylor A. Leach
Taylor A. Leach

Reputation: 2324

Maybe try this answer:

import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {

var webView: WKWebView!

override func loadView() {
    let webConfiguration = WKWebViewConfiguration()
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.uiDelegate = self
    view = webView
}
override func viewDidLoad() {
    super.viewDidLoad()

    let myURL = URL(string: "https://www.apple.com")
    let myRequest = URLRequest(url: myURL!)
    webView.load(myRequest)
}}

And check the docs from Apple! https://developer.apple.com/documentation/webkit/wkwebview

Upvotes: 2

Related Questions