Created
October 27, 2016 10:40
-
-
Save czwen/9f59d06b943c795b993596f718fdfaa9 to your computer and use it in GitHub Desktop.
Set Custom User-Agent Of UIWebView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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