Nigel Denny
Nigel Denny

Reputation: 189

Google disallowed_useragent in WKWebView

I'm trying to use WebView for a page in my app but when trying to log into google I get an error. enter image description hereI am aware that google requires a known OS browser to log onto their services but there are ways around their OAuth. Where in my code should it be implemented to have google believe that WebView is a browser.

    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)

    }
}

Upvotes: 6

Views: 6821

Answers (3)

Berkoo
Berkoo

Reputation: 65

I think the user agents that Google looks at vary depending on the current version of Safari.

this works for me

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

Upvotes: 0

Alex_Burla
Alex_Burla

Reputation: 810

Just use this:

    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"

Upvotes: 1

Razib Mollick
Razib Mollick

Reputation: 5052

Just set the correct value of your mobile safari agent in webConfiguration.applicationNameForUserAgent. Try with the following code.

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
    }

Upvotes: 14

Related Questions