Load desktop version WKWebView iOS 9

心已入冬 提交于 2019-12-01 13:43:33

Swift 4:

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
      super.viewDidLoad()
      self.webView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17"
}
Pablo Romero

One way to resolve this it's by setting applicationNameForUserAgent property of WKWebViewConfiguration.

The default value is "Mobile/13C75", but you can set it with "Chrome/23.0.1271.6 Safari/537.11" or just "Chrome Safari" and you will get the desktop version of the requested URL.

WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];    
wkWebConfig.applicationNameForUserAgent = @"Chrome Safari";    
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero
                                        configuration:wkWebConfig];

To help any who find themselves here for an answer. The solution was

UserDefaults.standard.register(defaults: ["UserAgent" : "Chrome Safari"])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!