+(void)setWebViewUserAgent:(NSString *)suffix { UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero]; NSString *oldAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; NSLog(@"old agent :%@", oldAgent); if ([CommonHelper isEmpty:suffix]) suffix = @"TTSWebView"; NSString *newAgent = [oldAgent stringByAppendingFormat:@"%@-iOS-%@",suffix,[CommonHelper appVersion]]; NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary]; }
在应用启动时调用一次即可.
转载请注明出处.
写博客的目的:记录,升华,量变到质变