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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With