【问题标题】:AVAudioSession Passcode-lock stops AVAudioRecorder on iOS8AVAudioSession Passcode-lock 在 iOS8 上停止 AVAudioRecorder
【发布时间】:2015-01-08 03:43:32
【问题描述】:

我遇到了与后台录制相关的意外问题(特别是当屏幕变为密码锁定时)。总之,我的 AVAudioRecorder 应用程序似乎在前台、后台(切换应用程序时)和屏幕关闭时(但在激活密码锁之前)正确录制。

如果我延迟密码锁定(设置 > 密码 > 需要密码 > 4 小时 .etc),那么录制在前台/后台/应用程序切换/屏幕关闭.etc 中没有问题,但是当密码锁启动时,录音会损坏。

我基本上是使用 AVAudioRecorder 代码来录制音频,并遵循指南通过在 app.plist 中设置“UIBackgroundModes/audio”设置来确保后台录制,这似乎在背景(即出现红色录音栏),但在密码激活时失败,即用户按下电源按钮并需要输入密码才能访问设备。

我的代码设置为通过“AVAudioSessionInterruptionNotification”处理音频中断,并且设置了 AVAudioSession 'withOptions:AVAudioSessionCategoryOptionDuckOthers',以最大限度地减少外部事件对后台录制的影响。 p>

[测试程序]

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

    1. [Success-CASE-1] 'Start Recording' for 7mins Leave Screen On and App active/visible (ie not running in background after recording is started) >> Recording works and after press 'Stop Recording' audio已保存并可播放。

    2. [Success-CASE-2] 'Start Recording' for 7mins Leave Screen On and Switch apps (ie run in background with screen most On and Red-Recording bar display after recording is started) >> Recording works and按下“停止录制”后,音频将被保存并可播放。

    3. [Failure-CASE]“开始录制”7 分钟关闭屏幕(即应用程序在后台运行且设备屏幕关闭)>> 屏幕关闭 7 分钟后,设备在屏幕打开时需要密码.录制意外停止,损坏无法播放。

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

    1. [Repeat-Failure-CASE with Adjusted Passlock] 'Start Recording' for 7mins 关闭屏幕(即应用程序在后台运行,设备屏幕关闭)>> 屏幕关闭 7 分钟后,设备开启(未通过这次需要锁)。录音没问题,效果很好,可以播放。

Failure-CASE 和 Repeat-Failure-CASE 的唯一区别是不需要锁屏密码。

[注释]

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

..

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

还有其他人遇到过这个问题吗?因为它很奇怪。

谢谢

【问题讨论】:

    标签: ios objective-c audio-recording avaudiorecorder avaudiosession


    【解决方案1】:

    您的音频文件(在沙盒中)可能在密码锁定时受到 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];
    

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

    【讨论】:

    • Man u 救了我的命....谢谢你,一直在寻找这个问题的原因!苹果好像一天比一天更糟,连日志信息都没有描述是什么问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多