我正在obj-c中制作一个ios应用程序,我想要给我发电子邮件。但该应用程序在此行崩溃:[synthesizer speakUtterance:utterance];
这是说出电子邮件的方法:
-(void) speakEmails {
NSString *currentEmail = [summariesList objectAtIndex:0];
NSLog(@"Email Being Spoken: %@", currentEmail);
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:currentEmail];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
[synthesizer speakUtterance:utterance];
}
这就是NSString currentEmail
:
Email Being Spoken: {
date = Today;
sender = "tony@starkindustries.com";
summary = "Blah Blah Blah Blah";
type = regular;
}
我一直收到错误-[__NSCFDictionary length]: unrecognized selector sent to instance 0x16528b30
。我不知道为什么会这样。任何帮助表示赞赏。
答案 0 :(得分:0)
您将currentEmail
设置为字典(解析的JSON)而不是字符串。试试这个:
NSString *currentEmail = [[summariesList objectAtIndex:0] objectForKey:@"sender"];
为了确保将来不会发生这种情况,您可以像这样快速检查:
-(void) speakEmails {
NSString *currentEmail = [summariesList objectAtIndex:0];
NSLog(@"Email Being Spoken: %@", currentEmail);
if (currentEmail != nil)
{
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:currentEmail];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
[synthesizer speakUtterance:utterance];
}
}