Use AVSpeechSynthesizer on iOS 7, but keep compatibility for iOS 6

Hi, I understand that TTS is only available in iOS 7, but in the past I used a lot of apis to check if the class is accessible and managed to maintain compatibility in previous versions, but it does not seem to work with AVSpeechSynthesizer, can you help me use TTS for iOS 7 and maintain compatibility by disabling it in iOS 6, thank you very much.

Here is my code but it does not work

    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
    }
}

I already bundled avfoundation in my project and set the target iOS 6 for deployment, and it seems to work only when launched on iOS 7 devices, if its iOS 6 works.

here is the error message i get

dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate
+4
1

. :

  • (),
  • Link Binary With Libraries
  • AVFoundation.framework

Setting AVFoundation.framework from Required to Optional

, ( Apple).

+6

All Articles