WKWebView user-agent (swift)

家住魔仙堡 提交于 2020-05-16 03:10:06

问题


I'm trying to get the user-agent from WKWebView by using swift,

let webView = WKWebView(frame: .zero) useragentlabel.text = webView.configuration.applicationNameForUserAgent

but it return Mobile/15E148, it s can be that the user-agent ?

thanks


回答1:


[self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable result, NSError * _Nullable error) {

 }];

The result is userAgent




回答2:


This gets the user agent:

let userAgent = webView.customUserAgent!


来源:https://stackoverflow.com/questions/58337691/wkwebview-user-agent-swift

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