-UIApplication.shared.openURL(url)
-UIApplicartion.shared.open(url,options: [:],completionHandler: nil)
我可以在 iOS9 和 iOS10 中使用这两个选项吗?
iOS9 和/或 iOS10 是否支持UIApplication.shared.openURL(url)
?
你可以
试试这个
guard let url = URL(string: "http://www.google.com") else {
return //be safe
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
是的,您必须通过将它们置于这样的状态来使用两者,
func open(scheme: String) {
if let url = URL(string: scheme) {
if #available(iOS 10, *) { // For ios 10 and greater
UIApplication.shared.open(url, options: [:],
completionHandler: {
(success) in
print("Open (scheme): (success)")
})
} else { // for below ios 10.
let success = UIApplication.shared.openURL(url)
print("Open (scheme): (success)")
}
}
}
guard let url = URL(string: "https://www.google.com/") else { return }
if #available(iOS 10.0, *) {
UIApplication.shared.open(url)
} else {
// Fallback on earlier versions
let svc = SFSafariViewController(url: url)
present(svc, animated: true, completion: nil)
}
当我想在iOS 9及更高版本的Safari浏览器中打开URL时,我使用了这个。