“openURL”在 iOS 10.0 中已被弃用:请在 Swift 3 中使用 openURL:options:completionHandler: 代替
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42389649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead in Swift 3
提问by SwiftDeveloper
I have working open webLink url codes in Swift3
but when I use it gives me this warning;
我有打开的 webLink url 代码,Swift3
但是当我使用它时,它给了我这个警告;
'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead
“openURL”在 iOS 10.0 中已弃用:请改用 openURL:options:completionHandler:
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.
谢谢你。
回答by Anbu.Karthik
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.
如需更多参考,请参阅此示例链接。
回答by Sergey
Try to use this:
尝试使用这个:
UIApplication.shared.open(URL(string: "\(myUrl)")!)