2

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

timbroder
  • 858
  • 1
  • 13
  • 25

1 Answers1

0

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
timbroder
  • 858
  • 1
  • 13
  • 25
  • @RyanPoolos odd, it's still working for me in our app. What is yours doing? – timbroder May 19 '17 at 21:21
  • I'm not 100% sure, but from what I can tell its ignoring `@media screen and (min-width: 480px)` and just rendering the desktop version zoomed in and cropped. I have lots of other sites working as expected, but this seems to be the only one with @media and the only one failing. So suspect its related but until its fixed I can't confirm haha – Ryan Poolos May 20 '17 at 11:23
  • @RyanPoolos can you share a link? Does it work if you open it in mobile safari? – timbroder May 23 '17 at 16:09
  • If I save it to an html file and open it in Mac Safari Mobile Test Mode it works. Its an email not a website so its not easy to just open it directly. It works in the iOS Mail client. But in a WKWebView it has issues. – Ryan Poolos May 24 '17 at 10:48