1、对于osx,设置WebView的UserAgent的方法

    WebView *webview = [[WebView alloc]initWithFrame:NSZeroRect];
    NSString *olderUserAgent = [webview stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
    NSString *newUserAgent = @"Appended Custom User Agent";
    NSString *userAgent = [NSString stringWithFormat:@"%@ %@",olderUserAgent,newUserAgent];
    [webview setCustomUserAgent:userAgent];

2、对于osx,设置WKWebView的UserAgent的方法

[webView setValue:userAgent forKey:@"customUserAgent"];//对于osx10.11以及以上使用该函数
[webView setValue:userAgent forKey:@"applicationNameForUserAgent"];//对于osx10.10以及以下使用该函数,该函数是私有函数

3、对于ios,设置WebView或WKWebView的UserAgent的方法

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
相关资源
相似解决方案