iphone - iPhone 应用程序中的用户代理

标签 iphone analytics tracking ads

如果我想在 iPhone 应用中添加第三方代码(分析或广告),默认用户代理是什么?我该如何更改它?

最佳答案

更改请求 header 中的用户代理,如下所示:

NSString* userAgent = @"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5 BAVM/1.0.0";
NSURL* url = [NSURL URLWithString:@"http://www.stackoverflow.com/"];
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"%@",result);

获取当前用户代理/查找特定浏览器的用户代理:
http://www.useragentstring.com/

用户代理通常没有区别。
使用默认的就可以了,或者更好,不用担心。

关于iphone - iPhone 应用程序中的用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5622662/

相关文章:

android - Google Analytics 不显示购买但显示事件

apache-flex - Flex IFrame上的Google Analytics(分析)

iphone - CCTouchDispatcher 优先级问题?

iphone - 处理 iPhone 上的注销功能

android - 为同一应用程序、多个平台设置 Google Analytics 的最佳方式

azure - Application Insights 中的用户流和 channel 功能之间的差异

iphone - 如何将 UIButton 传递给函数并在那里创建...?

ios - Xcode.embeddedframework

android - Google Analytics 事件报告中的时间延迟

google-analytics - 如何使用 Google Analytics 跟踪单页应用程序