简体   繁体   English

如何在不初始化UIWebView或WKWebView的情况下获取WKWebView的UserAgent?

[英]How to get UserAgent for WKWebView without initializing UIWebView or WKWebView?

I know we can initialize a UIWebView or WKWebView then inject JavaScript to get the value of navigator.userAgent , however that requires the initialization of UIWebView , which takes much time . 我知道我们可以初始化UIWebViewWKWebView然后注入JavaScript以获取navigator.userAgent的值,但是这需要初始化UIWebView ,这需要很多时间 Is there a way to get UserAgent faster? 有没有一种方法可以更快地获得UserAgent?

If you need the exact userAgent string, you can ignore this answer. 如果您需要确切的 userAgent字符串,则可以忽略此答案。

If, however, you are interested in the info encoded inside the userAgent string, you can get most/all of them with other APIs... eg you get the device type with UIDevice.current.model ; 但是,如果您对userAgent字符串中编码的信息感兴趣,则可以使用其他API来获取大多数/全部信息,例如,使用UIDevice.current.model获得设备类型; the browser type is Safari/Mobile Safari (didn't check what's the exact string but this value is unlikely to change); 浏览器类型为Safari /移动Safari(无法检查确切的字符串,但是该值不太可能更改); the platform obviously is iOS; 该平台显然是iOS; etc. 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM