Last active
May 25, 2020 18:04
-
-
Save revblaze/b6bb05c6a8825549ac6a6ca84e8bbfb5 to your computer and use it in GitHub Desktop.
WebKit Observer: URL
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
var webViewURLObserver: NSKeyValueObservation? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
webViewURLObserver = webView.observe(\.url, options: .new) { [weak self] webView, change in | |
let url = "\(String(describing: change.newValue))" | |
self?.urlDidChange(urlString: url) | |
} | |
} | |
func urlDidChange(urlString: String) { | |
if let url = urlString as? String { | |
if url.contains("404") { | |
print("Error 404: Page not found") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment