我已经高度集成 Speechkit
如果是这种情况,我认为创建两个单独的 viewController 可能更容易——或更合乎逻辑——你可以根据#available(iOS 10.0, *)
假设您将ViewController2
基于点击另一个 ViewController 中的按钮来呈现(在代码片段中,我称之为PreviousViewController
):
class PreviousViewController: UIViewController {
//...
@IBAction func presentApproriateScene(sender: AnyObject) {
if #available(iOS 10.0, *) {
// present the ViewController that heavily integrated with Speechkit
// maybe by perfroming a segue:
performSegueWithIdentifier("segue01", sender: self)
// or maybe by getting the it from the storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc1 = storyboard.instantiateViewControllerWithIdentifier("vc1")
presentViewController(vc1, animated: true, completion: nil)
} else {
// present the ViewController that does not suupport Speechkit
// maybe by perfroming a segue:
performSegueWithIdentifier("segue02", sender: self)
// or maybe by getting the it from the storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc2 = storyboard.instantiateViewControllerWithIdentifier("vc2")
presentViewController(vc2, animated: true, completion: nil)
}
}
//...
}
此外,您可以在声明变量时使用它:
class ViewController: UIViewController {
//...
if #available(iOS 10.0, *) {
private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!
} else {
// ...
}
//...
}
但是,正如您所提到的,如果您与 Speechkit 进行了“高度”集成,我认为制作两个 Viewcontroller 会更合乎逻辑。
希望这有帮助。