Load desktop version WKWebView iOS 9

后端 未结 3 1743
耶瑟儿~
耶瑟儿~ 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];
    
    0 讨论(0)
  • 2020-12-20 07:33

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

    UserDefaults.standard.register(defaults: ["UserAgent" : "Chrome Safari"])
    
    0 讨论(0)
  • 2020-12-20 07:40

    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"
    }
    
    0 讨论(0)
提交回复
热议问题