Reputation: 1867
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
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