public func isLoggedIn() -> Bool{
var returnValue:Bool = true
let wb: WKWebView = {
let webView = WKWebView()
return webView
}()
wb.load(URLRequest(url:URL(string:"https://www.google.com/" )!))
wb.evaluateJavaScript("document.body.backgroundColor") { (result, error) in
if let result = result {
print ("result")
print(result)
if (result as! String == ""){
returnValue = false
}
}
}
return returnValue
}
I want to evaluateJavaScript from WKWebview with that function but I always get the error
Optional(Error Domain=WKErrorDomain Code=3 "The WKWebView was invalidated" UserInfo={NSLocalizedDescription=The WKWebView was invalidated})
error getting color
Optional(Error Domain=WKErrorDomain Code=3 "The WKWebView was invalidated" UserInfo={NSLocalizedDescription=The WKWebView was invalidated})
this function is in a class userManager and is called in another UIViewController class with if (userManager().isLoggedIn())
I don't know why it won't work and sorry if that's just a dumb question. Thank you already for helping.
edit: Thanks to the people in the comments and for everyone that try something similar like I do then just use http request How do I make an HTTP request in Swift?