Search code examples
iosuiwebviewsafarimobile-safari

Open website in UIWebView as Safari?


For example website 'm.freemyapps.com' denies all the browsers and even UIWebView and requests Safari only.

Is it possible to make my app present itself as Safari?


Solution

  • If I understand your question correctly, you can do any of the two things-

    1) You can redirect the user to leave the app and open the mobile site in Safari.

    2) For mobile site support, the UIWebView might need to add additional User-Agent header fields in the request, mimicking Safari. e.g.

    NSURL *url = [NSURL URLWithString:@"m.freemyapps.com"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setValue:@"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like   Gecko) Version/3.0 Mobile/1A543a Safari/419.3" forHTTPHeaderField:@"User-Agent"];
    [webview loadRequest: request];
    

    In most of the cases, this solution should work. If this does not, you should find out with the server side implementation of the particular mobile site as to whether it requires additional headers to be sent.