首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVAudioSession密码-锁在iOS8上停止AVAudioRecorder

AVAudioSession密码-锁在iOS8上停止AVAudioRecorder
EN

Stack Overflow用户
提问于 2014-11-11 14:43:53
回答 1查看 489关注 0票数 3

我有一些与背景录音有关的意外问题(特别是当屏幕被密码锁定时)。在总结中,我的AVAudioRecorder应用程序似乎正确地记录在前台、后台(切换应用程序时)和屏幕关闭时(但在激活通行证锁之前)。

如果我延迟密码锁(设置>密码>要求密码>4小时.etc),那么录音工作时不会出现前景色/背景/应用程序切换/屏幕关闭.etc的问题,但当记录中的通行证锁启动时会损坏。

我基本上使用AVAudioRecorder代码来记录音频,并遵循了在app.plist中设置‘UIBack基power / audio’设置的指导原则,以确保背景录音,这似乎在背景中有效(即出现红色记录栏),但当pass代码激活时,即用户按下电源按钮,并需要输入密码才能访问设备时,就会失败。

我的代码被设置为通过‘AVAudioSessionInterruptionNotification’处理音频中断,而AVAudioSession是设置为尽量减少外部事件对背景录音的影响。

测试程序

  • 密码锁(iPhone 5/OS8.1>设置>密码>要求密码>5分钟后)

代码语言:javascript
复制
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.

  • 密码锁(iPhone 5/iOS8.1>设置>密码>要求密码> 15分钟后)

代码语言:javascript
复制
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

  1. 使用XCode 6.1进行测试,在iPhone 4/5/6、iPad Mini 2 (iOS8.1)上测试相同的问题。
  2. 代码是标准AVAudioRecorder代码,AVAudioSession设置类似于:http://www.jacopretorius.net/2013/04/record-and-playback-audio-in-ios.html

.

希望信息有所帮助,经过了大量的尝试和错误才达到这一点。

还有其他人经历过这个问题吗?因为很奇怪。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-03-15 16:13:07

当密码锁定时,您的音频文件(在沙箱中)可能受到iOS的保护;如果屏幕没有设置密码,则一切正常;

尝试以下几点:

代码语言:javascript
复制
        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];

或者,将证书中的数据保护设置为“关闭”。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26867491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档