UIWebView项目中在多个webview加入自定义全局UserAgent
来源:互联网 发布:java context 编辑:程序博客网 时间:2024/06/06 02:39
在工程中如果需要加入自定义的自定义的UserAgent值,一般用作服务器或者浏览器客户端判断。
在一个工程中会遇到多个UIWebView窗口的情况,每次都设定UserAgent的情况。
所以这种情况是一般采用全局的定义。
一般在XxxxAppDelegate.m中加入全局定义:
+ (void)initialize{ NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3 MYXAPP/0.01", @"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];}
其中“MYXAPP/0.01”为自定义串,用来给服务器判断使用。
当然也可以加入其他的值,比如一些不同的特定的信息等。
在UIWebView中也常常需要取得UserAgent用来判断是不是本应用发出的请求,还是服务器发起的300等。
NSString* userAgent = [request valueForHTTPHeaderField:@"User-Agent"];NSRange range = [userAgent rangeOfString:@"MYXAPP"];if( range.location != NSNotFound ){ NSLog( @"User-Agent:%@", userAgent );}
0 0
- UIWebView项目中在多个webview加入自定义全局UserAgent
- iOS UIWebView 自定义 UserAgent
- iOS UIWebView 自定义 UserAgent
- iOS UIWebView 自定义 UserAgent
- iOS UIWebView 自定义 UserAgent
- 自定义webView的userAgent
- Android Webview自定义UserAgent
- 获取 UIWebview 的 Useragent,以及附加自定义字段到 Useragent
- 获取 UIWebview 的 Useragent,以及附加自定义字段到 Useragent
- iOS UIWebView 自定义请求头 UserAgent
- 在Global Object Services (GOS) 中加入自定义项目
- iOS中修改UIWebView的UserAgent
- android给ScrollView中显示多个控件 --公司项目 在左边栏 加入滚条
- 在UIWebView中添加自定义编辑菜单
- 在项目中加入freemarker
- UIWebView自适应高度,适合一个页面多个WebView
- UIWebView更改UserAgent
- iOS UIWebView 修改userAgent
- Python3.4.1爬虫编写笔记
- iOS7 新UI 一
- 通过金矿模型介绍动态规划
- 数据结构之字符串
- HDU 4080 UVaLive 4513 - Stammering Aliens (字符串hash)
- UIWebView项目中在多个webview加入自定义全局UserAgent
- [leetcode]107.Binary Tree Level Order Traversal II
- 第八周项目二计算加班费
- iOS7 新UI 二
- 我是如何通过别人的淘宝店,在45天内成功招到600学员的
- 【树链剖分】 POJ 3237 Tree
- 什么是操作数
- 100万 素数表 (is2120)
- css中padding中样式的顺序含义