【问题标题】:AVSpeechUtterance as UILocalNotification soundAVSpeechUtterance 作为 UILocalNotification 声音
【发布时间】:2014-05-07 14:27:20
【问题描述】:

您好,感谢您阅读本文!

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

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

非常感谢!

【问题讨论】:

    标签: ios ios7 background uilocalnotification avspeechsynthesizer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多