OGeek|极客世界-中国程序员成长平台

标题: ios - 如何从 iOS 8 开始获取浏览器 UserAgent 字符串? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 17:54
标题: ios - 如何从 iOS 8 开始获取浏览器 UserAgent 字符串?

除了使用以下方法之外,还有其他方法可以获取 iOS 浏览器 UserAgent 字符串吗?请帮忙。

WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[webView loadHTMLString"<html></html>" baseURL:nil];

[webView evaluateJavaScript"navigator.userAgent" completionHandler:^(id __nullable userAgent, NSError * __nullable error) {
        NSLog(@"%@", userAgent);
}];



Best Answer-推荐答案


试试这个:

UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString"navigator.userAgent"];

关于ios - 如何从 iOS 8 开始获取浏览器 UserAgent 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34341485/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4