Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change user-agent for good

I have been able to change the user-agent by using

- (BOOL)webView:(UIWebView *)webView2 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

NSMutableURLRequest *req = (NSMutableURLRequest *)request;
NSString *versionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];

NSLog(@"user agent = %@", [req valueForHTTPHeaderField: @"User-Agent"]);

if ([req valueForHTTPHeaderField:@"User-Agent"] != NULL) {

    [req setValue:[NSString stringWithFormat:@"%@ %@", versionString, [req valueForHTTPHeaderField:@"User-Agent"]] forHTTPHeaderField:@"User-Agent"];
    NSLog(@"user agent = %@", [req valueForHTTPHeaderField: @"User-Agent"]);

   return YES
    }
}

But when I go to this website on the device http://whatsmyuseragent.com/ my user-agent hasn't changed. Is there a way to change the user-agent for good?

like image 273
Clinton Walsh Avatar asked Nov 21 '25 09:11

Clinton Walsh


1 Answers

After playing around for a really long time, I discovered that you can change the User Agent without rooting. Not sure if this helps you if you are building an app.

like image 118
Mitch Avatar answered Nov 22 '25 22:11

Mitch