How do I set a custom useragent string in a WKWebView? I\'m trying to embed the version of my app so that my server-side can see what features are available. I found the followi
In my swift 3 case, I need entire app using a custom userAgent, here is my solution in AppDelegate. Here using UIWebview is because I don't need to set up the WKWebViewConfiguration, because I just only need the userAgent string
fileprivate func setupGlobalWebviewUserAgent() {
let webview = UIWebView()
var newUserAgent = webview.stringByEvaluatingJavaScript(from: "navigator.userAgent")
newUserAgent = newUserAgent?.appending("custom user agent")
let dictionary = Dictionary(dictionaryLiteral: ("UserAgent", newUserAgent))
UserDefaults.standard.register(defaults: dictionary)
}