Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Agent in an iPhone App

What is the default user agent if I want to add third party code (analytics or ads) in an iPhone app and how can I do to change it?

like image 907
Matthieu Avatar asked Apr 11 '11 14:04

Matthieu


1 Answers

Change the user-agent in the header of your request like this:

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);

Get current user-agent / lookup user-agents for specific browsers:
http://www.useragentstring.com/

The user-agent generally makes no difference.
Just use the default one, or better, don't worry about it.

like image 130
Anne Avatar answered Nov 05 '22 07:11

Anne