WKWebView only showing desktop site

筅森魡賤 提交于 2019-12-02 05:36:19

问题


I just migrated from UIWebView and my new WKWebView will only show the desktop version of the site I'm loading. My UIWebView showed the responsive site appropriately.

I have tried forcing a mobile User-Agent and confirmed that it is coming in on to the server

let userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11A465 Twitter for iPhone"
webView.customUserAgent = userAgent

Does anyone have any other ideas I can try? Thanks


回答1:


I don't have control over the CSS of the page I'm displaying.

It was using the following to calculate breakpoints:

width=device-width, initial-scale=1

@media screen and (min-width: 650px)

Adding this to the template that uses that CSS solved it for me:

<meta name="viewport" content="width={{ $width }}, shrink-to-fit=YES">

Where {{ $width }} is:

UIScreen.mainScreen().bounds.size.width


来源:https://stackoverflow.com/questions/39182746/wkwebview-only-showing-desktop-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!