自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone獲得User-Agent(UA)信息的方法

移動(dòng)開發(fā) iOS
User-Agent(簡稱UA)是HTTP請(qǐng)求頭部用來標(biāo)識(shí)客戶端信息的字符串, 包括操作系統(tǒng), 瀏覽器等信息. 為了建立手機(jī)客戶端的信息數(shù)據(jù)庫, 需要從手機(jī)的http請(qǐng)求中取到這一字符串.

如果你需要獲取Android手機(jī)的UA信息,請(qǐng)移步這里Android獲得UA信息的方法

iPhone中取到UA信息的方法如下:

1.利用瀏覽器控件UIWebView建立一個(gè)http請(qǐng)求

2.在請(qǐng)求建立的期間, 建立一個(gè)新的事件循環(huán)用來判斷UA信息是否已經(jīng)建立

3.在發(fā)送http請(qǐng)求之前截獲UA信息, 并且取消這一http請(qǐng)求 ;)

獲取iPhone UA的代碼如下:

  1. UIWebView *_webView; 
  2. NSString *userAgent; 
  3.  
  4. - (void)createHttpRequest { 
  5.     _webView = [[UIWebView alloc] init]; 
  6.     _webView.delegate = self; 
  7.     [_webView loadRequest:[NSURLRequest requestWithURL: 
  8.     [NSURL URLWithString:@"http://www.eoe.cn"]]]; 
  9.     NSLog(@"%@", [self userAgentString]); 
  10.     [_webView release]; 
  11.  
  12. -(NSString *)userAgentString 
  13.     while (self.userAgent == nil)  
  14.     { 
  15.         NSLog(@"%@", @"in while"); 
  16.         [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 
  17.         } 
  18.     return self.userAgent; 
  19.  
  20. -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
  21.     if (webView == _webView) { 
  22.     self.userAgent = [request valueForHTTPHeaderField:@"User-Agent"]; 
  23.     // Return no, we don't care about executing an actual request. 
  24.     return NO; 
  25.     return YES; 
  26.  
  27. - (void)dealloc { 
  28. [userAgent release]; 
  29.     [super dealloc]; 
  30.   

程序在iPhone4.1模擬器中運(yùn)行結(jié)果如下:

2010-12-21 12:52:38.302 UATest[6722:207] in while

2010-12-21 12:52:38.305 UATest[6722:207] in while

2010-12-21 12:52:38.307 UATest[6722:207] in while

2010-12-21 12:52:38.307 UATest[6722:207] in while

2010-12-21 12:52:38.308 UATest[6722:207] in while

2010-12-21 12:52:38.309 UATest[6722:207] in while

2010-12-21 12:52:38.312 UATest[6722:207] Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Mobile/8B117

責(zé)任編輯:張葉青 來源: eoe Android開發(fā)者社區(qū)
相關(guān)推薦

2021-12-28 07:20:44

UA網(wǎng)絡(luò)協(xié)議

2011-12-13 14:19:32

iPhone信息圖

2009-03-27 14:40:38

AndroidiPhoneFlash

2017-10-25 14:44:37

PackageManaApp信息

2013-08-21 11:31:21

iPhone圖片方法

2009-08-25 09:40:05

思科網(wǎng)絡(luò)認(rèn)證證書思科網(wǎng)絡(luò)認(rèn)證

2018-05-11 09:17:57

CIO

2012-04-26 13:17:56

iPhone應(yīng)用發(fā)布登錄銀行信息

2012-04-11 16:56:55

蘋果

2011-07-20 15:42:18

iPhone 劃動(dòng)條

2019-02-12 09:10:53

2011-08-05 16:58:25

iPad iPhone UIImagePic

2012-05-10 17:16:07

信息圖iPhoneAndroid

2022-05-11 11:26:14

烏克蘭惡意鏈接化學(xué)攻擊

2011-08-03 17:27:40

iPhone UIScrollVi

2021-08-30 11:07:32

iPhone存儲(chǔ)空間

2011-03-29 10:22:35

Zabbix Agen安裝

2011-03-29 14:37:47

Zabbix Agen配置

2009-11-07 19:09:35

Windows 7優(yōu)惠

2024-08-05 15:39:06

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)