0

I am trying to open various WebView links in a Safari View Controller.

So from within a WebView (Swift) I need to be able to open all external links in Safari View Controller, with the exception of internal links that will open within the WebView (self).

  • What's your question? – koen Sep 15 '15 at 12:34
  • Hi, I need all external URL links within my WebView to to open in Safari View Controller. (Xcode, Swift). But keep all internal links within the WebView. Any help with this would be appreciated.
 
 I have tried this but with no results
 

 func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool { if navigationType == UIWebViewNavigationType.LinkClicked { if (request.URL!.host! == "example.com"){ return true } else { UIApplication.sharedApplication().openURL(request.URL!) return false } } return true } – user2029893 Sep 15 '15 at 16:20
  • You can find your answer here: http://stackoverflow.com/questions/9746260/how-can-i-open-an-external-link-in-safari-not-the-apps-uiwebview – koen Sep 15 '15 at 17:39
  • Hi, thanks for the reply I have tried this but I think it is a bit out of date. – user2029893 Sep 15 '15 at 19:56
  • Maybe you can elaborate on what exactly goes wrong? "I have tried this but with no results" is not very descriptive. – koen Sep 15 '15 at 20:25

1 Answers1

1
//MARK: Button Click on open with SafariViewController

private var urlString:String = "https://google.com"

@IBAction func openWithSafariVC(sender: AnyObject)
{
    let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!)
    svc.delegate = self
    self.presentViewController(svc, animated: true, completion: nil)
}
//MARK: SafatriViewConroller Dismiss 

func safariViewControllerDidFinish(controller: SFSafariViewController)
{
    controller.dismissViewControllerAnimated(true, completion: nil)
}
hypercrypt
  • 15,389
  • 6
  • 48
  • 59
Bhavin Chauhan
  • 611
  • 4
  • 17