Change UserAgent in iOS WebView apps πŸ“²

Want to identify WebView client accesses? Makes sense, you can use it for tracking/analytics purposes and for separating web browser and WebView client accesses to optimize/modify the style or content.

The default WebView UserAgent on iOS looks like this:

Mozilla/5.0 (iPad; U; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile

So let’s change it:


var useragent_custom = "Custom UserAgent here"
let customuseragent = [
"UserAgent" : useragent_custom

UserDefaults.standard.register(defaults: customuseragent)


If you use WebViewGoldΒ Xcode template, you do not need to worry about the whole custom UserAgent procedure, even for separate iPhone/iPad user agents – just enter the customized UserAgent(s) in the WebViewController.swift configuration file:

Any questions? Just email us! πŸ™‚