xcode WKWebView中的Google disallowed_useragent

xlpyo6sf  于 2023-08-07  发布在  Go
关注(0)|答案(2)|浏览(121)

我试图在我的应用程序中使用WebView的页面,但当试图登录到谷歌我得到一个错误。

我知道谷歌需要一个已知的操作系统浏览器来登录他们的服务,但有办法绕过他们的OAuth。在我的代码中,应该在哪里实现,让谷歌相信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)

    }
}

字符串

2wnc66cl

2wnc66cl1#

只需在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
    }

字符串

oalqel3c

oalqel3c2#

就用这个:

self.webView.customUserAgent = "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Mobile Safari/537.36"

字符串

相关问题