Skip to content

Instantly share code, notes, and snippets.

@JanGorman
Last active August 29, 2015 14:04
Show Gist options
  • Save JanGorman/0b3d75c60b54238906ea to your computer and use it in GitHub Desktop.
Save JanGorman/0b3d75c60b54238906ea to your computer and use it in GitHub Desktop.
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let request = NSURLRequest(URL: NSURL(string: "http://www.duckduckgo.com"))
// let request = NSURLRequest(URL: NSURL(string: "http://www.google.com"))
// let request = NSURLRequest(URL: NSURL(string: "http://www.apple.com"))
webView.loadRequest(request)
}
func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
switch request.URL {
case let url where handleGoogle(url):
return false
case let url where handleApple(url):
return false
default:
return true
}
}
func handleGoogle(url: NSURL) -> Bool {
if url.absoluteString.hasPrefix("http://www.google") {
NSLog("I'm doing something else with google")
// Do something else with the URL and don't handle the request
return true
}
return false
}
func handleApple(url: NSURL) -> Bool {
if url.absoluteString.hasPrefix("http://www.apple") {
NSLog("I'm doing something else with apple")
// Do something else with the URL and don't handle the request
return true
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment