iOS UIWebView 修改user-agent
来源:互联网 发布:淘宝推广软文范文 编辑:程序博客网 时间:2024/05/17 23:46
我的需求是不光要能更改user-agent,而且要保留WebView 原来的user-agent 信息,也就是说我需要在其上追加信息。最终的解决方案如下:
//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];
这样,WebView在请求时的user-agent 就是我们设置的这个了,如果需要在WebView 使用过程中再次变更user-agent,则需要再通过这种方式修改user-agent, 然后再重新实例化一个WebView。
0 0
- iOS UIWebView 修改user-agent
- iOS UIWebView 修改user-agent
- iOS UIWebView 修改user-agent
- iOS UIWebView 修改user-agent
- iOS UIWebView 修改user-agent
- iOS UIWebView 修改user-agent
- ios不用创建UIWebView快速获取系统标准User-Agent
- android user agent修改
- 修改浏览器User-Agent
- 手动修改user-agent
- firefox 修改 user agent
- 修改浏览器user-agent
- 修改浏览器User-Agent
- 修改浏览器User Agent
- iOS中修改WebView默认的User Agent
- iOS中修改WebView默认的User Agent
- iOS中修改WebView默认的User Agent
- UIwebview 如何改User-Agent,让ipad uiwebview模拟iphone
- 【那些人追的干货】如何正确使用const,static,extern
- JMS实战——ActiveMQ
- HTTP协议详解
- FCK上传图片,接收图片
- java,jsp,servlet获取项目路径
- iOS UIWebView 修改user-agent
- ListView 使用
- UNDERSTANDING ANDROID GRAPHICS INTERNALS – SURFACEFLINGER (II)
- OpenCV实现RGB颜色空间和HSI颜色空间的相互转换
- 判断js对象是否拥有某属性
- ubuntu 16.04安装vmtool
- Login学习1
- Java删除文件夹下所有的文件和文件夹
- 计算机图形学(二)输出图元_18_显示列表_2_执行OpenGL显示表