英文:
WKWEBVIEW to display only mobile version of website
问题
iPad版本的我的应用通过WKWebView显示网站的桌面版本。我想强制WKWebView仅显示不同网站的移动版本。有任何想法?
英文:
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?
答案1
得分: 1
请问您是否已经尝试清除所有缓存并设置用户代理?
类似以下的方式:
let dataTypes = NSSet(array: [
WKWebsiteDataTypeDiskCache,
WKWebsiteDataTypeOfflineWebApplicationCache,
WKWebsiteDataTypeMemoryCache,
WKWebsiteDataTypeLocalStorage,
WKWebsiteDataTypeCookies,
WKWebsiteDataTypeSessionStorage,
WKWebsiteDataTypeIndexedDBDatabases,
WKWebsiteDataTypeWebSQLDatabases])
let date = NSDate(timeIntervalSince1970: 0)
WKWebsiteDataStore.defaultDataStore().removeData(ofTypes: dataTypes as! Set<String>, modifiedSince: date, completionHandler: { })
之后,在清理完成后,设置用户代理:
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"
也许您可以尝试这个方法,但可能不是最佳解决方案。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论