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
310 views
in Technique[技术] by (71.8m points)

swift - WKWebView not support some web-pages in iOS

I have a very simple web-view browser in my app, that works great except some sites. For example, https://apsny.market doesn't load a page because "browser is not supported". I tried to load this page in Safari and Chrome in iOS, and it works perfect as aspected. Maybe I need to set something in WKWebViewConfiguration, but I tried and nothing happened... I will appreciate any ideas. Thanks in advance!

And my simple code:

guard let myURL = URL(string: url) else { return }
let webConfiguration = WKWebViewConfiguration()
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
let myRequest = URLRequest(url: myURL)
webView.load(myRequest)
webView.navigationDelegate = self
question from:https://stackoverflow.com/questions/65953065/wkwebview-not-support-some-web-pages-in-ios

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

1 Answer

0 votes
by (71.8m points)

This site blocks mobile browsers by checking User-Agent header value in your request but you can change a User Agent for your web view to desktop one:

webView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36"

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

...