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

烂漫一生 提交于 2019-12-31 09:11:47

问题


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.


回答1:


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.




回答2:


Try to use this:

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


来源:https://stackoverflow.com/questions/42389649/openurl-was-deprecated-in-ios-10-0-please-use-openurloptionscompletionhandl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!