// 修改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}];
iOS 修改UIWebView的UserAgent
猜你喜欢
转载自blog.csdn.net/bravegogo/article/details/81119205
今日推荐
周排行