Last active
January 18, 2021 17:36
-
-
Save anatoliykant/2806be694eeda6837242251ec78a0152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private let sandboxURL = URL(string: "https://example.web.app/")! | |
class SomeViewController: UIViewController { | |
... | |
private lazy var webView: WKWebView = { | |
let configuration = WKWebViewConfiguration() | |
// configuration.userContentController.add(self, name: signInWithCustomToken) | |
let rect = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height) | |
let webView = WKWebView(frame: rect, configuration: configuration) | |
view.addSubview(webView) | |
webView.allowsBackForwardNavigationGestures = true | |
webView.scrollView.contentInsetAdjustmentBehavior = .never | |
webView.navigationDelegate = self | |
return webView | |
}() | |
} | |
extension SomeViewController: WKNavigationDelegate { | |
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
let token = "eyJhbGciOiJSUzI1Ni...GeFbBt6R7AxsEKfMFf4Ngq6f091pSMBx7o7mGw" | |
let javaScript = "window.app.signInWithCustomToken('\(token)')" | |
// let javaScript1 = "setTimeout(window.app.signInWithCustomToken('\(token)'), 1000);" | |
webView.evaluateJavaScript(javaScript) { (result, error) in | |
print(result) | |
print(error?.localizedDescription) | |
} | |
// JS web code | |
// window.app.signInWithCustomToken('token') | |
// .then(user => { | |
// // это будет выполнено если все ок и произодет логин | |
// }) | |
// .catch(err => { | |
// // это если будет ошибка | |
// }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment