'openURL' 在 iOS 10.0 中被弃用:请在 Swift 3 中使用 openURL:options:completionHandler:



我在 Swift3中有开放的weblink URL代码,但是当我使用它时会发出警告;

'OpenUrl'在iOS 10.0中弃用:请使用OpenUrl:options:poutterionhandler:而不是

我该如何解决,下面的代码。

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

谢谢。

使用

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

有关更多参考,请参阅此示例链接。

尝试使用以下方式:

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

最新更新