我有一些与背景录音有关的意外问题(特别是当屏幕被密码锁定时)。在总结中,我的AVAudioRecorder应用程序似乎正确地记录在前台、后台(切换应用程序时)和屏幕关闭时(但在激活通行证锁之前)。
如果我延迟密码锁(设置>密码>要求密码>4小时.etc),那么录音工作时不会出现前景色/背景/应用程序切换/屏幕关闭.etc的问题,但当记录中的通行证锁启动时会损坏。
我基本上使用AVAudioRecorder代码来记录音频,并遵循了在app.plist中设置‘UIBack基power / audio’设置的指导原则,以确保背景录音,这似乎在背景中有效(即出现红色记录栏),但当pass代码激活时,即用户按下电源按钮,并需要输入密码才能访问设备时,就会失败。
我的代码被设置为通过‘AVAudioSessionInterruptionNotification’处理音频中断,而AVAudioSession是设置为尽量减少外部事件对背景录音的影响。
测试程序
1. [Success-CASE-1] ‘Start Recording’ for 7mins Leave Screen On and App active/visible (i.e. not running in background after recording is started) >> Recording works and after pressing ‘Stop Recording’ audio is saved and can be played back.
2. [Success-CASE-2] ‘Start Recording’ for 7mins Leave Screen On and Switch apps (i.e. run in background with screen mostly On and Red-Recording bar displayed after recording is started) >> Recording works and after pressing ‘Stop Recording’ audio is saved and can be played back.
3. [Failure-CASE] ‘Start Recording’ for 7mins Switch Screen Off (i.e. app is running in background with devices screen off) >> After 7mins with Screen-Off, device requires passcode when screen is switched-On. Recording unexpectedly stops, becomes corrupt cannot be played back.
1. [Repeat-Failure-CASE with Adjusted Passlock] ‘Start Recording’ for 7mins Switch Screen Off (i.e. app is running in background with devices screen off) >> After 7mins with Screen-Off, device is switched on (no pass lock is needed this time). Recording is okay, works perfectly and can be played back.
只有失败案例和重复失败案例之间的区别是屏幕锁密码是不需要的。
Notes
.
希望信息有所帮助,经过了大量的尝试和错误才达到这一点。
还有其他人经历过这个问题吗?因为很奇怪。
谢谢
发布于 2015-03-15 16:13:07
当密码锁定时,您的音频文件(在沙箱中)可能受到iOS的保护;如果屏幕没有设置密码,则一切正常;
尝试以下几点:
NSDictionary *oldAttr = [[NSFileManager defaultManager]attributesOfItemAtPath:localFilePath error:nil];
NSMutableDictionary *newAttr = nil;
if (oldAttr){
newAttr = [[NSMutableDictionary alloc]initWithDictionary:oldAttr];
}else{
newAttr = [[NSMutableDictionary alloc]init];
}
[newAttr setObject:NSFileProtectionNone forKey:NSFileProtectionKey];
[[NSFileManager defaultManager] setAttributes:newAttr
ofItemAtPath:localFilePath
error:nil];或者,将证书中的数据保护设置为“关闭”。
https://stackoverflow.com/questions/26867491
复制相似问题