Google disallowed_useragent 在 WKWebView

Google disallowed_useragent in WKWebView

我正在尝试将 WebView 用于我的应用程序中的页面,但在尝试登录 google 时出现错误。 我知道 google 需要一个已知的 OS 浏览器才能登录他们的服务,但有一些方法可以绕过他们的 OAuth。应该在我的代码中的什么地方实现 google 相信 WebView 是一个浏览器。

    class CycleViewController: UIViewController, WKUIDelegate {

    var window: UIWindow?
    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        webView.backgroundColor = UIColor.clear
        webView.backgroundColor = UIColor(red: 0.0196, green: 0.4, blue: 0.2902, alpha: 1.0)

        webView.isOpaque = false
        let myURL = URL(string: "https://jwelsh19.wixsite.com/countryday")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)

    }
}

只需在 webConfiguration.applicationNameForUserAgent 中设置您的移动 Safari 代理的正确值。尝试使用以下代码。

override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }