简体   繁体   English

有没有办法如何在不重新实例化的情况下如何在iOS的wkwebview上设置UserAgent每个URL?

[英]are there way how to set UserAgent each url on wkwebview of iOS without re-instanciating?

I want to set UserAgent each url on wkwebview. 我想在wkwebview上设置UserAgent每个URL。 But i can't find. 但是我找不到。

let userAgentStr = "XXXXXXXXXXXXXXXXX"
    let dic:NSDictionary = ["UserAgent":userAgentStr]
    NSUserDefaults.standardUserDefaults().registerDefaults(dic as [NSObject : AnyObject])
    NSUserDefaults.standardUserDefaults().synchronize();

if above source is,my app will not be able to change UserAgent as long as i set nil wkwebview. 如果以上来源是,只要我将nil wkwebview设置为零,我的应用程序将无法更改UserAgent。

I don't want to re-instaciate wkwebview when i want to change useragent. 当我想更改useragent时,我不想重新安装wkwebview。

are there way how to set UserAgent each url on wkwebview of iOS without re-instanciating? 有没有办法如何在不重新实例化的情况下如何在iOS的wkwebview上设置UserAgent每个URL?

This was not possible with iOS 8 but on iOS 9 there actually is a customUserAgent on the WKWebView object. 这在iOS 8上是不可能的,但是在iOS 9上,实际上WKWebView对象上有一个customUserAgent So you can just set that and it will be set for every connection the WKWebView makes. 因此,您可以进行设置,并将为WKWebView进行的每个连接进行设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM