Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

ios - Difference between WKWebView and Safari?

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 !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...