在iOS 7上使用AVSpeechSynthesizer,但保留iOS 6的兼容性

你好,我了解TTS只在iOS 7中可用,但我过去通过检查类是否可用,并设法保留以前版本的兼容性,但使用AVSpeechSynthesizer它似乎没有工作,可以请帮我使用TTS for iOS 7,并通过在iOS 6中禁用它来保持兼容性,非常感谢。

这是我的代码,但似乎没有工作

if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)) { if([AVSpeechSynthesizer class]) { AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init]; AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text]; utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; utterance.rate = AVSpeechUtteranceDefaultSpeechRate/2; utterance.pitchMultiplier = 0.9; utterance.preUtteranceDelay = 0; utterance.postUtteranceDelay = 0; [synth speakUtterance:utterance]; } else { // Feature not available, do something else } } 

我已经在我的项目中链接了avfoundation并设置了部署目标iOS 6,而且它似乎只在iOS 7设备上运行,如果它的iOS 6崩溃的话。

这是我得到的错误消息

 dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate 

框架需要被弱联系起来。 请执行下列操作:

  1. 在Project Navigator(左边)中点击您的项目文件,在编辑器中打开您的项目
  2. 在编辑器中单击Build Phases选项卡
  3. 展开“ 链接二进制库”部分
  4. AVFoundation.frameworkRequired设置为Optional

将AVFoundation.framework从Required设置为Optional

此外,您可能希望更新您的版本检查更安全 (并由Apple推荐)。