Recently, I encountered this bug when updating the project. The following are the steps I took to solve it

1. Set a default UserAgent in the AppDelegate

let agentDefault = "Mozilla / 5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A366 YSL"
UserDefaults.standard.register(defaults: ["UserAgent": agentDefault])
UserDefaults.standard.synchronize()
Copy the code

2. In wkWebView, update UserAgent

webView.evaluateJavaScript("navigator.userAgent") {[weak self] (info, error) in
    guard let this = self else{
        return
    }
    if let str = info as? String{
        if str.hasSuffix("YSL"// Refresh webView this.loadurl ()return
        }
        let userString = str + "YSL"
        UserDefaults.standard.register(defaults: ["UserAgent": userString]) UserDefaults.standard.synchronize() this.webView.customUserAgent = userString CWLog (enclosing webView. CustomUserAgent)} / / to refresh the webView enclosing loadURL ()}Copy the code