"openURL" is deprecated in iOS 10.0: use OpenURL: options: completeHandler: instead in Swift 3

I have valid open webLink URLs in Swift3 , but when I use it, it gives me this warning;

'openURL' deprecated in iOS 10.0: use OpenURL: options: completeHandler: instead

How can I solve it, my codes are below.

 let myUrl = "http://www.google.com" if !myUrl.isEmpty { UIApplication.shared.openURL(URL(string: "\(myUrl)")!) } 

Thanks.

+26
ios swift3 uiwebview
source share
2 answers

Use as

  //inside scope use this let myUrl = "http://www.google.com" if let url = URL(string: "\(myUrl)"), !url.absoluteString.isEmpty { UIApplication.shared.open(url, options: [:], completionHandler: nil) } // or outside scope use this guard let url = URL(string: "\(myUrl)"), !url.absoluteString.isEmpty else { return } UIApplication.shared.open(url, options: [:], completionHandler: nil) 

For more reference see this sample link .

+71
source share

Try using this:

 UIApplication.shared.open(URL(string: "\(myUrl)")!) 
+3
source share

All Articles