-UIApplication.shared.openURL(url)
-UIApplicartion.shared.open(url,options: [:],completionHandler: nil)
我可以在iOS9和iOS10中使用这两个选项吗?
iOS9和/或iOS10是否支持UIApplication.shared.openURL(url)
?
答案 0 :(得分:4)
你可以试试这个
guard let url = URL(string: "http://www.google.com") else {
return //be safe
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
答案 1 :(得分:2)
是的,你必须把它们放在这样的条件下才能使用它们,
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)")
}
}
}
答案 2 :(得分:0)
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时,使用了此选项。