This code is supposed to load the Apple homepage, but instead shows a blank screen.
This happens with both HTTP and HTTPS URLs.
Code:
import UIK
You can try below code
import UIKit
import WebKit
class WebViewController: UIViewController {
var wkWebview: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
var Ycord : CGFloat = 0.0 // for top space
if UIScreen.main.bounds.height == 812 { //Check for iPhone-x
Ycord = 44.0
}
else {
Ycord = 20.0
}
let frame = CGRect(x: 0.0, y: Ycord, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height-Ycord)
self.wkWebview = WKWebView(frame: frame, configuration: WKWebViewConfiguration())
self.wkWebview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.wkWebview.uiDelegate = self
self.view.addSubview(self.wkWebview)
DispatchQueue.main.async {
self.wkWebview.load(URLRequest(url:URL(string: "https://www.apple.com")!))
}
}
}
Output