问题描述
显然 OpenURL
已在iOS 10中折旧。有没有人有任何关于为什么或可以解释下一步做什么的文档?我已经查看了Apple网站,发现了一些与OpenURL相关的内容,这就是他们现在所说的:
So apparently OpenURL
has been depreciated in iOS 10. Does anyone have any documentation on why or can explain what to do next? I looked on the Apple site already and found a few things pertaining to OpenURL and this is what they say to use now:
UIApplication.shared().open(url: URL, options: [String: AnyObject], completionHandler: ((Bool) -> Void)?)
有没有人有证据表明这是在Swift 3.0中使用OpenURL的新方法?此外,选项中将使用哪些值:
和 completionHandler:
参数?
Does anyone have any evidence that this is the new way to use OpenURL in Swift 3.0? In addition what values are to be used in the options:
and completionHandler:
parameters respectively?
推荐答案
如果您使用iOS10兼容代码更新应用程序,也可以使用条件检查:
You can also use conditional check if you are updating you app with iOS10 compatible code:
func open(scheme: String) {
if let url = URL(string: scheme) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:],
completionHandler: {
(success) in
print("Open \(scheme): \(success)")
})
} else {
let success = UIApplication.shared.openURL(url)
print("Open \(scheme): \(success)")
}
}
}
用法:
open(scheme: "tweetbot://timeline")
这篇关于iOS10中的OpenURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!