Reputation: 1
Unable to load "https://dev-react.ndh01.com" this url only in WKWebView in swift. But it is loading in browser and Android Webview
Upvotes: 0
Views: 897
Reputation: 39
you are not doing anything wrong and technically your webpage is loading properly, but this website is not optimized for all screen sizes, you can verify this by rotating your test device whether you using a simulator or physical device
import UIKit
import WebKit
class WebViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
preferences.javaScriptCanOpenWindowsAutomatically = true
let configuration = WKWebViewConfiguration()
configuration.preferences = preferences
let webview = WKWebView(frame: .zero, configuration: configuration)
view.addSubview(webview)
webview.load(URLRequest(url: URL(string: "https://dev-react.ndh01.com")!))
webview.translatesAutoresizingMaskIntoConstraints = false
webview.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
webview.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
webview.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
webview.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
}
if you are using a simulator try pressing Cmd + right/left arrow to rotate the device to landscape
you will find a screen showing your web page
Upvotes: 1