matt
matt

Reputation: 535850

desktop browsing in iOS 13 with WKWebView?

According to WWDC 2019 video 203, I should be able to see desktop browsing in a full-screen WKWebView on an iPad. But I'm not seeing it. For example, when I go to google in my WKWebView, I'm clearly seeing the mobile version of the site.

I've tried everything the video suggests. I've set the applicationNameForUserAgent, and the web inspector shows that it is being set as they advise in the video:

"5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/1.0 MyBrowser/1.0"

I've also implemented the navigation delegate to request .desktop mode:

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) {
    preferences.preferredContentMode = .desktop
    print("asking for desktop version")
    decisionHandler(.allow, preferences)
}

That method is being called. But I'm still seeing the mobile version of the site.

When I go to the same site in Safari on the same iPad, or if I use an SFSafariViewController, I do see the desktop version of the site, as advertised. How can I get that version of the site in my WKWebView?

Upvotes: 4

Views: 3015

Answers (2)

yaslam
yaslam

Reputation: 108

I'm disappointed at this bug of WKWebView on iPadOS (iPad iOS13).

This is the code that get each version programmatically, generates a string in the format indicated by @matt, and adds it to user agent.

let systemVersion = UIDevice.current.systemVersion
let webkitVersion = (Bundle(for: SFSafariViewController.self).object(forInfoDictionaryKey: "CFBundleVersion") as? String) ?? "605.1.5"
webConfig.applicationNameForUserAgent = "Version/\(systemVersion) Safari/\(webkitVersion)"

Upvotes: 1

matt
matt

Reputation: 535850

I was able to get it to work by using "Version/13.0.1 Safari/605.1.15" as my applicationNameForUserAgent string.

(Where did I get that string? Basically I simply stole it from the SFSafariViewController.)

This seems like a bug. Apple's video implies that I should not have to lie about who the user agent is in order to get desktop browsing.

Upvotes: 5

Related Questions