码迷,mamicode.com
首页 > Web开发 > 详细

给UIWebView调整UserAgent字段

时间:2016-05-11 11:15:35      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

+(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];
}

在应用启动时调用一次即可.

给UIWebView调整UserAgent字段

标签:

原文地址:http://www.cnblogs.com/decwang/p/5481030.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!