Skip to content

Instantly share code, notes, and snippets.

@Pranit-Harekar
Created September 17, 2018 19:50
Show Gist options
  • Save Pranit-Harekar/9981bece1db034e421c88aec6eaaa399 to your computer and use it in GitHub Desktop.
Save Pranit-Harekar/9981bece1db034e421c88aec6eaaa399 to your computer and use it in GitHub Desktop.
func landingPageWillStartLoading() -> Future<Void, NSError> {
return Future { complete in
let js = "document.body.contains(document.getElementById(\"loading\"));"
let deadline = Date.init(timeIntervalSinceNow: 10)
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [unowned self] timer in
if (Date() > deadline) {
timer.invalidate()
complete(.failure(self.loadInitialPageError))
}
if !self.webView.isLoading {
self.webView.evaluateJavaScript(js) { (result, error) in
if error == nil && result.toString() == "0" {
timer.invalidate()
complete(.success())
}
}
}
}.fire()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment