Ios AVSpeechSynthesizer赢得';手机锁定时无法工作
当手机锁定时,我尝试使用Ios AVSpeechSynthesizer赢得';手机锁定时无法工作,ios,objective-c,avspeechsynthesizer,Ios,Objective C,Avspeechsynthesizer,当手机锁定时,我尝试使用AVSpeechSynthesizer,但当我锁定屏幕时,音频停止。我用的是模拟器,不是真正的设备。我在这个网站上看到了其他几个类似的问题,我遵循了他们的建议,但仍然不起作用 在app delegate中,我将音频会话类别设置为AVAudioSessionCategoryPlayback - (void)configureAudioSession{ NSError *error = NULL; [[AVAudioSession sharedInstance
AVSpeechSynthesizer
,但当我锁定屏幕时,音频停止。我用的是模拟器,不是真正的设备。我在这个网站上看到了其他几个类似的问题,我遵循了他们的建议,但仍然不起作用
在app delegate中,我将音频会话类别设置为AVAudioSessionCategoryPlayback
- (void)configureAudioSession{
NSError *error = NULL;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];
if(error) {
NSLog(@"Error setting category of audio session: %@",error.description);
}
error = NULL;
[[AVAudioSession sharedInstance] setActive:YES error: &error];
if (error) {
NSLog(@"Error activating audio session: %@",error.description);
}
}
我在项目设置->功能->背景模式下检查了“音频和播放”模式
有人能告诉我如何让它工作吗?大约一个月前,我可以通过这篇文章让它工作:
基本上,您需要在应用程序的.plist文件中输入。我不确定这是否能在模拟器上运行,所以您可能希望在实际设备上测试它。以下是我如何让AVSpeechSynthesizer在手机闲置、手机锁定或应用程序进入后台时继续说话的。(第8章) 步骤1)打开info.plist并添加“所需背景模式”键。在此数组中,添加一个名为“应用程序使用AirPlay播放音频或流式播放音频/视频”的字符串 步骤2)将以下内容添加到应用程序delegate didFinishLaunchingWithOptions:
NSError *error = NULL;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
if(error) {
// Do some error handling
}
[session setActive:YES error:&error];
if (error) {
// Do some error handling
}
步骤3)在您的设备上运行并测试它