Skip to content

Instantly share code, notes, and snippets.

@czwen
Created October 27, 2016 10:40
Show Gist options
  • Save czwen/9f59d06b943c795b993596f718fdfaa9 to your computer and use it in GitHub Desktop.
Save czwen/9f59d06b943c795b993596f718fdfaa9 to your computer and use it in GitHub Desktop.
Set Custom User-Agent Of UIWebView
- (void)setDefaultWebViewUserAgent
{
// Get Default UserAgent.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *agent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
// Save it.
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@;my user-agent", agent], @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment