gpt4 book ai didi

ios - 阻止 Speechkit 使 iOS 9 设备崩溃

转载 作者:行者123 更新时间:2023-11-28 11:00:34 24 4
gpt4 key购买 nike

我已将 Speechkit 大量集成到我的一个应用程序的 View Controller 中。 Speechkit 仅在 iOS 10 上可用,但我还需要我的应用程序在 iOS 9 设备上运行。

现在,我的应用程序在 iOS 9 设备上启动时崩溃;如何防止 Speechkit 使 iOS 9 及更早版本崩溃?我可以创建两个单独的 View Controller 文件,还是必须在每个 Speechkit 引用周围放置 if#available(iOS 10, *) {

编辑:除了这个我还能做什么?

import Speech
class ViewController2: UIViewController, SFSpeechRecognizerDelegate {

if #available(iOS 9, *) { // ERROR: Expected Declaration
private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!
}

func doSomeStuffWithSpeech() {
...
}

...

}

最佳答案

I have heavily integrated Speechkit

如果是这样,我认为创建两个独立的 viewController 可能更容易 - 或者更合乎逻辑 - 您可以根据 #available(iOS 10.0, *) 决定应该查看哪个p>

假设您将根据点击另一个 ViewController 中的按钮显示 ViewController2(在代码片段中,我将其称为 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 会更合乎逻辑。

希望这对您有所帮助。

关于ios - 阻止 Speechkit 使 iOS 9 设备崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40793055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com