Load desktop version WKWebView iOS 9

后端 未结 3 1787
耶瑟儿~
耶瑟儿~ 2020-12-20 06:46

Up until recently

let url = NSURL (string:http://asite.com)        
let request = NSMutableURLRequest(URL: url!)         

//iOS loads the mobile version of         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 07:21

    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];
    

提交回复
热议问题