'WKWebView is not loading perticular url in swift

Unable to load "https://dev-react.ndh01.com" this url only in WKWebView in swift. But it is loading in browser and Android Webview



Solution 1:[1]

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

landscape image shows you webpage

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shyank_dev