Fix UserAgent in WebView apps on iPad Pro on iPadOS 13 and higher ⚙️

 

Want to identify your WebView app on your server? That makes sense; you can use it for many different reasons, e.g., to match the style or content with the app.

 

The default WebView UserAgent on iOS looks like this:

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

In WebView apps you can modify it this way:

 

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

UserDefaults.standard.register(defaults: customuseragent)

 

The problem: On iPadOS 13 (and higher), iPad Pro will override the UserAgent afterward again to present itself as a macOS system to deliver “desktop browsing experience” for users (“it’s not a bug, it’s a feature”). But here are the good news: If you use the WebViewGold Xcode template, you can still override the UserAgent for all devices (including iPad Pro on iPadOS/iOS 13 and higher). Enter the customized UserAgent(s) in the WebViewController.swift configuration file & you are ready to go:

Happy Coding! Any questions? Just email us! 🙂