ios - AVSpeechUtterance 作为 UILocalNotification 声音

标签 ios ios7 background uilocalnotification avspeechsynthesizer

您好,感谢您阅读本文!

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

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

非常感谢!

最佳答案

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

关于ios - AVSpeechUtterance 作为 UILocalNotification 声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23520572/

相关文章:

ios - 仅一种原型(prototype)单元格的自动表格 View 单元格高度

ios - UITableView 没有显示它应该显示的 Realm 对象

ios - 检查 watch 应用程序是否处于最前面状态

jquery - If/Then 语句 Jquery

ios - iOS 模拟器可以创建与设备匹配的 Game Center 吗?

android - Android开机时启动后台服务

iphone - IOS 调用 didFinishLaunchingWithOptions 的条件

ios - 带有 Swift 滑动菜单的空白菜单按钮

ios - 如何在第二个 VC 中使用第一个 VC 的方法?

ios - 以编程方式检查是否在 iOS 7 上设置了密码锁