问题
Hello I Understand TTS is only available in iOS 7 but i used many apis in the past by checking if the class is available and managed to retain compatibility on previous versions but with AVSpeechSynthesizer it doesn't seem to work, can you please help me use TTS for iOS 7 and retain compatibility by disabling it in iOS 6, thank you very much.
Here is my code but it doesn't seem to 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've already linked avfoundation in my project and set deployment target iOS 6 and it seems to work only when runing on iOS 7 devices if its iOS 6 it crashes.
here is the error message i get
dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate
回答1:
The framework needs to be be weak linked. Do the following:
- Click your project file in the Project Navigator (on the left) to open your project in the editor
- Click the Build Phases tab in the editor
- Expand the Link Binary With Libraries section
- Set AVFoundation.framework from Required to Optional

Additionally, you might want to update your version check with one that's safer (and recommended by Apple).
来源:https://stackoverflow.com/questions/21102500/use-avspeechsynthesizer-on-ios-7-but-retain-compatibility-for-ios-6