1

I have an app in which I have different web views for different flows (which are being managed by different teams). My problem is that I want to set different user agents for different flows, ie. User-Agent = "XYZ" for some flow and User-Agent = "ABC" for some other flow.

I have tried using the following code, after reading from some StackOverflow links, before I init the controller containing UIWebView, but I read somewhere that I cannot modify User-Agent this way.

- (void)setUserAgentForWebView
{
    UIWebView *dummyWebView = [[UIWebView alloc] initWithFrame:CGRectZero];
    NSString *secretAgent = [dummyWebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
    NSString *newUserAgent = [NSString stringWithFormat:@"%@/IPHONE_V3",secretAgent];
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

I use this code to set different User-Agent for different flows according to my need. But it seems that User-Agent is not modified because I can't get desired results.

Kindly guide me on this.

sudhanshu-shishodia
  • 1,100
  • 1
  • 11
  • 25
  • possible duplicate of [UIWebView iOS5 changing user-agent](http://stackoverflow.com/questions/8487581/uiwebview-ios5-changing-user-agent) – duncanc4 Apr 27 '15 at 05:33
  • I don't want to run this code once, I want to run it every time a different UIWebView is called. I already mentioned this (I want to have different User-Agent for different flows). – sudhanshu-shishodia Apr 27 '15 at 05:37

0 Answers0