David Cao
David Cao

Reputation: 545

iOS User-Agent for Requesting a Desktop Site

I'm trying to request a desktop site using NSURLRequest. I found from How does Chrome's "Request Desktop Site" option work? that the solution seems to be to set the User-Agent header field to mimic a desktop User-Agent string. However, simply doing

NSURL *url = [NSURL URLWithString:@"http://www.facebook.com"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10" forHTTPHeaderField:@"User-Agent"];
[_webView loadRequest:req];
[self.view addSubview:_webView];

doesn't seem to lead me anywhere. My question is is this a correct User-Agent string I can use? Or is perhaps the request overriding the headers sometime after this?

UPDATE: I tried visiting http://www.useragentstring.com/ instead of facebook to see the User-Agent string at the time of the request. It seems that it's

Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H141

instead of the string I set. This leads me to think that the request is overriding the User-Agent sometime during the request.

Upvotes: 2

Views: 2548

Answers (1)

iggy_the_fisk
iggy_the_fisk

Reputation: 76

The UIWebView you're using to send the request is adding its own user agent, overriding yours. To change the user agent for your web view, try this Change User Agent in UIWebView (iPhone SDK)

Upvotes: 2

Related Questions