I am trying to make an OS X app that displays a WebView of a mobile website using basic webview code, problem is I want this WebView to automatically load the mobile versions of whatever website it’s on.
WebFrame *mainFrame = [web1 mainFrame];
NSURL *url = [NSURL URLWithString:@"http://www.website.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[mainFrame loadRequest:request];
So my question is, is there anything that I can add to the above code to make this web view identify itself to the server of what ever website it is on as a mobile browser, thus automatically loading the mobile version of any website it is on? I have already tried looking for the answer to this for myself online and haven’t had the least bit of luck finding the answer.
Thank you in advance for any and all help!
Yes
Use an
NSMutableURLRequestinstead of a simpleNSURLRequest, so you can alter it and use itssetValue:forHTTPHeaderField:method to set the “User-Agent” HTML Header field to the User-Agent of MobileSafari.For the User-Agent String to use, it depends on the version of MobileSafari you want to “emulate” (which version/device you want to make the server belives you are).
See here for some of the UA strings possible