What is the default user agent if I want to add third party code (analytics or ads) in an iPhon开发者_运维技巧e app and how can I do to change it?
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.
精彩评论