Reputation: 595
How can I load desktop versions of web sites(such as google, facebook) rather than mobile versions?
Upvotes: 0
Views: 2048
Reputation: 31
Why are you going through all this hassle? This is the wrong/LONG approach.
Just create an NSMutableRequest
and set the useragent
inside it and not in the UIWebView
. Then just load the request with a UIWebView
normal/non-private loadRequest:
-function.
Upvotes: 3
Reputation:
Edit: Disregard all this. Yaniv's right. Just load an NSMutableURLRequest
to the UIWebView
instance using the - loadRequest:
message and set the "User-Agent"
header to whatever you want.
NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:someUrl];
[rq setValue:@"Some desktop user-agent" forHTTPHeaderField:@"User-Agent"];
[webView loadRequest:rq];
For your information, a good choice for a desktop user-agent string is that of Chrome - it's also WebKit-based, as Safari, so WebKit-specific extensions will work. So try setting the user-agent string to
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11
Original post:
You can try spoofing the user agent of UIWebView but I can't guarantee that such a fat hack will let you through the thin gate of AppStore...
void *object_getIvarPtr(id obj, const char *name)
{
Ivar iv = object_getInstanceVariable(obj, name, NULL);
off_t offset = ivar_getOffset(iv);
return (char *)obj + offset;
}
// In some initialization routine, after having created the web view
id webViewInternal = *(id *)object_getIvarPtr(someWebView, "_internal");
id webBrowserView = *(id *)object_getIvarPtr(webViewInternal, "browserView");
id webKitWebView = [webBrowserView webView];
NSString *desktopUAStr = @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11"
[webKitWebView setCustomUserAgent:desktopUAStr];
Upvotes: 2