问题
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