3

こんにちは、これを読んでくれてありがとう!

フォアグラウンドで、私のアプリはAVSpeechUtterance時間指定されたイベントのために iOS7 を再生します。バックグラウンドで、.wav ファイル名を のsoundNameプロパティに渡しますUILocalNotification。これはすべて機能します。

AVSpeechUtteranceの音として使う方法はあり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 に答える