Dmytro Dmytro - 3 months ago 49
Swift Question

How can I request a desktop version of a webpage using UIWebView in Swift 3.0?

Actually I tried to find it from other sources, but there is nowhere clear answer that will be working perfectly. (example : How to request the desktop version of a webpage in Swift 2)

Please, help up. Provide the answer with the workable example.


A WKWebView should solve your problem - you can define it in your code. Do this:

var webView : WKWebView!
override func loadView() {

    let config = WKWebViewConfiguration()
    webView = WKWebView(frame: self.view.frame, configuration: config)
    self.webView!.uiDelegate = self
    webView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
    //load URL here
    let url = NSURL(string: "")!
    webView.load(URLRequest(url: url as URL))