bablack
bablack

Reputation: 129

WKWEBVIEW to display only mobile version of website

the iPad version of my app displays the desktop version of websites through a WKWEBVIEW. I would like to force the WKWEBVIEW to only show the mobile version of the different websites.

Any idea?

Upvotes: 1

Views: 1247

Answers (1)

fabriciomasiero
fabriciomasiero

Reputation: 134

Do you already tried to clear all caches and set user agent?

Something like this:

let dataTypes = NSSet(array: [
    WKWebsiteDataTypeDiskCache,
    WKWebsiteDataTypeOfflineWebApplicationCache,
    WKWebsiteDataTypeMemoryCache,
    WKWebsiteDataTypeLocalStorage,
    WKWebsiteDataTypeCookies,
    WKWebsiteDataTypeSessionStorage,
    WKWebsiteDataTypeIndexedDBDatabases,
    WKWebsiteDataTypeWebSQLDatabases])
let date = NSDate(timeIntervalSince1970: 0)
WKWebsiteDataStore.defaultDataStore().removeDataOfTypes(websiteDataTypes as! Set<String>, modifiedSince: date, completionHandler:{ })

and after this cleaning, set a user agent

webview.customUserAgent = "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5"

Maybe you should try this one, but maybe isn't the best solution

Upvotes: 1

Related Questions