Yanis
Yanis

Reputation: 21

How use User-Agent to make iPhone download file as a chrome?

My code is:

NSMutableURLRequest* req = [[[NSMutableURLRequest alloc] initWithURL:url]
                                autorelease];

NSString *userAgent = @"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13";    
[req setValue:userAgent forHTTPHeaderField:@"User-Agent"];

NSURLResponse* response = nil;
NSError* error = nil;
NSData* fff = [NSURLConnection sendSynchronousRequest:req
                                     returningResponse:&response
                                                 error:&error];

NSLog(@"size : %d", [fff length]);

I prepare to make iPhone download file as chrome. But it doesn't work! I don't know why...

Upvotes: 0

Views: 271

Answers (1)

David Williams
David Williams

Reputation: 11

This userAgent String works: "Mozilla/5.0 (iPhone; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/4.0 Mobile/8C148 Safari/533.17"; Use the Swizzle classes.

By the way.. your string: @"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13"; Has Windows; U; Windows NT 5.1 in there and that's not what you want for an iphone

David

Upvotes: 1

Related Questions