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

前端之家收集整理的这篇文章主要介绍了在iOS 7上使用AVSpeechSynthesizer但保留iOS 6的兼容性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
你好我理解TTS仅在iOS 7中可用,但我过去使用了很多apis,检查该类是否可用并设法保留以前版本的兼容性,但是使用AVSpeechSynthesizer它似乎不起作用,请你帮我使用适用于iOS 7的TTS并通过在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

解决方法

框架需要弱联系.请执行下列操作:

>单击Project Navigator(左侧)中的项目文件,在编辑器中打开项目
>单击编辑器中的“构建阶段”选项卡
>展开Link Binary With Libraries部分
>将AVFoundation.framework从required设置为Optional

此外,您可能希望使用one that’s safer更新版本检查(并由Apple推荐).

猜你在找的Xcode相关文章