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
WKWebView
Swift 3 example:
let userAgentValue = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
webView.customUserAgent = userAgentValue
Note to those who try to do this using Storyboard or Interface Builder: Unfortunately, Xcode doesn't currently support using WKWebView
in Storyboards (Xcode version 8.3.2), so you have to add the web view manually in your code.
UIWebView
Swift 3 example:
UserDefaults.standard.register(defaults: ["UserAgent": userAgentValue])