9

I'm creating a special app where I'm using a WKWebView. But I have one problem... WKWebView is acting different (outdated browser) than Safari (iOS version of Safari ofc).

If I visit adidas.com/yeezy on Safari, there is no problem. But when I visit this site in WKWebView, it says that the browser is not modern enough.

I really need to fix this otherwise my app can't work.

Does anyone has a solution to make WKWebView "modern" ?

Thanks !

MaximVW
  • 203
  • 1
  • 4
  • 12

2 Answers2

5

I believe it's just configuration. check out WKPreferences

I guess that if you enable whatever you can, you'll find the requested feature.. I'll check adidas to see if I find something special needed

EDIT: Second option, you may trick the website that you are a different browser. just set customUserAgent, see here.

You can see a working example in your Mac.

1) Open Safari

2) Development

3) User Agent

4) Other

Copy and past it to your code, Good luck!

Take for an example the next value:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5


EDIT: Example for swift 5 and XCode 10.2.1

Thanks Mr.G

testWebView.customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Mobile/15E148 Safari/604.1"
Yitzchak
  • 3,303
  • 3
  • 30
  • 50
  • Didn't try 1st option, but 2nd option did the trick, thank you very much ! – MaximVW Nov 12 '17 at 19:17
  • How do you set the customUserAgent property? And how do you change configurations using WKPreferences ? – iPhoneDeveloper Dec 27 '17 at 08:18
  • @iPhoneDeveloper the customUserAgent is a property of WKWebView, just set it to your preferred browser. Search in Google "useragent examples" to find the correct value that make the site think that you browser is. – Yitzchak Dec 27 '17 at 09:24
  • 1
    This is how you set in swift 5, Xcode 10.2.1: ```testWebView.customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Mobile/15E148 Safari/604.1" ``` – Mr. G Jul 14 '19 at 12:54
1

I found this question while investigating a similar issue: my website works fine in Safari but not in Chrome for iOS.

If you visit http://whatsmyuseragent.org, you will likely notice that your WKWebView is using a different webkit version (60x.x.x) than Safari.

nicbou
  • 1,047
  • 11
  • 16