美文网首页
修改userAgent

修改userAgent

作者: 念念不忘的 | 来源:发表于2016-12-06 14:06 被阅读11次

WebView修改userAgent
http://www.cnblogs.com/jiangshengkai/p/5863834.html
在启动时,比如在AppDelegate 中添加如下代码:

//get the original user-agent of webview
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *oldAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSLog(@"old agent :%@", oldAgent);
//add my info to the new agent
NSString *newAgent = [oldAgent stringByAppendingString:@" Jiecao/2.4.7 ch_appstore"];
NSLog(@"new agent :%@", newAgent);
//regist the new agent
NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];

相关文章

网友评论

      本文标题:修改userAgent

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