- (void)setUserAgent { //get the original user-agent of webview NSString *oldAgent = [self.shareWebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; NSLog(@"old agent :%@", oldAgent); NSInteger lent = oldAgent.length; NSString *UA = [oldAgent
substringFromIndex:lent-7]; if (![UA isEqualToString:@"app-ios"]) { //add my info to the new agent NSString *newAgent = [oldAgent stringByAppendingString:@" app-ios"]; NSLog(@"new agent :%@", newAgent); //regist the new agent NSDictionary *dictionnary = [[NSDictionary
alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary]; [super loadView]; }}
webView修改UA
最新推荐文章于 2024-03-11 13:48:49 发布