xcode 适用于 iOS 9 及更低版本的 UIApplication.shared().open() 的替代方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38712284/
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
What is the alternate method for UIApplication.shared().open() for iOS 9 and less?
提问by Rachit Rawat
Previously i was using XCode 8 beta 3 and testing it on iOS 10 device. But now i want my app to support previous versions of iOS. When i am trying to run it on iOS 9 device after decreasing the deployment target from project settings, this particular method is showing error since it's only available for iOS 10.0 or newer:
以前我使用 XCode 8 beta 3 并在 iOS 10 设备上测试它。但现在我希望我的应用程序支持以前版本的 iOS。当我从项目设置中减少部署目标后尝试在 iOS 9 设备上运行它时,此特定方法显示错误,因为它仅适用于 iOS 10.0 或更高版本:
UIApplication.shared().open((url as URL), options: [:], completionHandler: nil)
回答by Mohammed Shakeer
Use below code as it available in lower versions of iOS
使用下面的代码,因为它在较低版本的 iOS
if UIApplication.sharedApplication().canOpenURL(url!) {
UIApplication.sharedApplication().openURL(url!)
}
Swift 3.0 and above
Swift 3.0 及以上
// for versions iOS 10 and above
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:])
}
// for versions below iOS 10
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.openURL(url)
}