Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead in Swift 3 [duplicate]

I have working open webLink url codes in Swift3 but when I use it gives me this warning;

'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead

How can I resolve it, my codes under below.

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

Thank you.

like image 713
SwiftDeveloper Avatar asked Feb 22 '17 11:02

SwiftDeveloper


2 Answers

Use like

 //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.

like image 102
Anbu.Karthik Avatar answered Sep 22 '22 07:09

Anbu.Karthik


Try to use this:

UIApplication.shared.open(URL(string: "\(myUrl)")!) 
like image 21
Sergey Avatar answered Sep 22 '22 07:09

Sergey