本文共 907 字,大约阅读时间需要 3 分钟。
// 修改WebView的UserAgent
UIWebView *webView = [UIWebView new]; NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; NSString *appUserAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]]; userAgent = [userAgent stringByAppendingString:@" "]; userAgent = [userAgent stringByAppendingString:appUserAgent]; [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent" : userAgent, @"User-Agent" : userAgent}];转载地址:http://nlxvb.baihongyu.com/