如何在iOS上获取用户代理? [英] How to get the user agent on iOS?

查看:141
本文介绍了如何在iOS上获取用户代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS上是否有办法获取设备的用户代理?我不想硬编码,因为我需要所有设备的用户代理,我需要将用户代理附加到URL。

Is there a way on iOS to get the user agent of the device? I don't want to hard code it since I need the user agent for all devices and I need to append the user agent to a URL.

谢谢。

推荐答案

在iOS中确定用户代理的一种更简单的方法是直接从 UIWebView 使用此SO帖子的已接受答案。引用该答案:

A simpler way to ascertain the user agent in iOS is to get it directly from a UIWebView using the accepted answer to this SO post. To quote that answer:


解决方案是创建一个UIWebView,然后使用javascript来提取用户代理。

The solution was to create a UIWebView and then just use javascript to pull out the user agent.

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


这篇关于如何在iOS上获取用户代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆