-1

all links open in WebView and I can not go back to the previous view of the APP.

How can I specify that links are opened in the Safari and not in the WebView of my APP?

What do I have to change in my code?

if let url = URL(string: "https://www.example.com") {
    let request = URLRequest(url: url)
    webView.loadRequest(request)
}

Many thanks for your efforts!

greeting Bjorn

tgogos
  • 23,218
  • 20
  • 96
  • 128
Björn
  • 1
  • 4

2 Answers2

0

Use this code below:

In Objective-C:

NSURL * url = [NSURL URLWithString:@"https://www.example.com"];
if ([[UIApplication sharedApplication] canOpenURL:url ])
{
    [[UIApplication sharedApplication] openURL:url];
}

In Swift:

if let url = URL(string: "https://www.example.com") {
    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.openURL(url)
    }
}
A K M Saleh Sultan
  • 2,403
  • 2
  • 22
  • 28
0

Try this code. I think it useful for you:

if #available(iOS 10.0, *) {
    UIApplication.shared.open(yourUrl, options: [:], completionHandler: nil)
} else {
    UIApplication.shared.openURL(yourUrl)
}
Son Pham
  • 1,516
  • 1
  • 14
  • 22