+(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]; }
在应用启动时调用一次即可.
时间: 2024-10-31 09:02:28