3

您好,感谢您阅读本文!

在前台,我的应用程序AVSpeechUtterance为定时事件播放 iOS7。在后台,我将一个 .wav 文件名传递给 .wav 的soundName属性UILocalNotification。这一切都有效。

有没有办法AVSpeechUtterance用作 a 的声音UILocalnotification?我希望前景与背景相同。

非常感谢!

4

1 回答 1

0

appdelegate.m在文件中创建此方法。不要忘记在 Appdelegate.h 中导入 AVFoundation/AVSpeechSynthesis.h

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
                                                        message:notification.alertBody
                                                       delegate:self cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }
    AVSpeechUtterance *utterance = [AVSpeechUtterance
                                    speechUtteranceWithString:[NSString stringWithFormat:@"%@",notification.alertBody]];
    AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
    utterance.volume = 10;
    utterance.rate = 0.2;
    utterance.pitchMultiplier = 1;
    [synth speakUtterance:utterance];

    // Request to reload table view data
    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];

    // Set icon badge number to zero
    application.applicationIconBadgeNumber = 0;
}
于 2014-06-05T10:41:20.120 回答