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

IosUiwebviewSwift3

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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.

Solution 2 - Ios

Try to use this:

UIApplication.shared.open(URL(string: "\(myUrl)")!)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSwiftDeveloperView Question on Stackoverflow
Solution 1 - IosAnbu.KarthikView Answer on Stackoverflow
Solution 2 - IosSergeyView Answer on Stackoverflow