0

Possible Duplicate:
UIWebView iOS5 changing user-agent

There is requirement to open some website in desktop version and some in mobile version. how to set different user agent in UIWebView's delegate 'webView:shouldStartLoadWithRequest:navigationType'. Thanks in advance.

Community
  • 1
  • 1
Nik
  • 682
  • 1
  • 8
  • 27

1 Answers1

-1

Refer allow-overriding-of-user-agent-on-uiwebview link.

Refer iphone-ipad-get-user-agent-for-uiwebview link

Also refer uiwebview-ios5-changing-user-agent SO link.

Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • Prince thanks for reply. is it possible to change user agent at run time? – Nik Aug 29 '12 at 06:10
  • yes it possible to change user agent at run time in - (BOOL)webView:(UIWebView *)aWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { – Paresh Navadiya Aug 29 '12 at 06:11
  • 1
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)Type { NSString *url = [[req URL] absoluteString]; NSString *userAgent = [url rangeOfString:@"yahoo.com"].location != NSNotFound ? @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7" : mUserAgent; NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:userAgent, @"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; return YES; } – Nik Aug 29 '12 at 07:26
  • is there any problem in this code? – Nik Aug 29 '12 at 07:26
  • is this safe for App Store acceptance? thanks! – zonabi Jul 11 '15 at 23:30
  • Yes its app store safe to change user agent in UIWebView – Paresh Navadiya Jul 13 '15 at 07:05