美文网首页
关于iOS获取User-Agent的方法

关于iOS获取User-Agent的方法

作者: amoyb1ooooooo | 来源:发表于2016-10-20 00:23 被阅读0次

- (void)viewDidLoad {

[superviewDidLoad];

UIButton*btn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

btn.frame=CGRectMake(100, 100, 80, 40);

[btnsetTitle:@"连接数据"forState:UIControlStateNormal];

[btnaddTarget:selfaction:@selector(pressBtn)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:btn];

// _data = [[NSMutableData alloc]init];

// Do any additional setup after loading the view, typically from a nib.

}

-(void)pressBtn{

/**获取系统的UA */

UIWebView* webView = [[UIWebViewalloc]initWithFrame:CGRectZero];

NSString*userAgentString = [webViewstringByEvaluatingJavaScriptFromString:

@"navigator.userAgent"];

NSLog(@"useragent = %@",userAgentString);

}

此为获得当前模拟器或手机的UA的方法,写在viewDidLoad中便可

相关文章

网友评论

      本文标题:关于iOS获取User-Agent的方法

      本文链接:https://www.haomeiwen.com/subject/uecfuttx.html