直到最近
let url = NSURL (string:http://asite.com)
let request = NSMutableURLRequest(URL: url!)
//iOS loads the mobile version of asite.com which does not have the required DOM so we force the desktop version by setting new value forHTTPHeadrField
let newUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11"
request.setValue(newUserAgent, forHTTPHeaderField: "User_Agent")
let config = WKWebViewConfiguration()
//even though we dont need to see it the webpage needs to appear but we set its frame to CGRectZero so its hidden from user
let ghostWebView : WKWebView = WKWebView(frame:CGRectZero, configuration: config)
ghostWebView.loadRequest(request)
这将强制站点的桌面版本。但是它刚刚停止工作。不知道确切的时间,但最近。
你知道为什么吗?
谷歌的结果也显示了一些用处
“用户代理”
对于httpheaderfield和其他
“用户代理”
两者有什么区别?
更新:
我通过将用户代理字符串更改为
“Mozilla/5.0(Macintosh;Intel Mac OS X 10_10_1)应用程序WebKit/537.36
(KHTML,像壁虎)铬/41.0.2227.1 Safari/537.36“
我从中得到的
http://www.useragentstring.com
所以我的新问题是这些用户代理字符串多久更改一次,我的应用程序是否有办法自动更新到最新的?
最佳答案
银行代码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"
}
关于swift - 加载桌面版WKWebView iOS 9,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33434153/