Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

    }
}
like image 248
Nigel Denny Avatar asked Dec 18 '22 20:12

Nigel Denny


1 Answers

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
    }
like image 171
Razib Mollick Avatar answered Jan 05 '23 09:01

Razib Mollick