Aj.
Aj.

Reputation: 31

AVAudioSession Passcode-lock stops AVAudioRecorder on iOS8

I’m having unexpected issues related to background recording (specifically when the Screen becomes Passcode-locked). In Summary my AVAudioRecorder app seems to record correctly in the foreground, background (when switching apps) and when the screen is off (but before the pass-lock is activated).

If i delay passcode-lock (Settings > Passcode > Require Passcode > 4 hours .etc) then the recording works without a problem in foreground/background/app switching/screen off .etc, but when the pass-lock kicks in the recording becomes corrupt.

I'm basically using AVAudioRecorder code to record the audio, and have followed the guidelines by setting 'UIBackgroundModes/audio' setting in app.plist to ensure background recording, which seems to work in the background (i.e. Red Recording Bar appears) but fails when pass-code becomes active i.e. user pushes the power button and is required to enter a passcode to access the device.

My code is set to handle audio-interrupts via ‘AVAudioSessionInterruptionNotification’ and AVAudioSession is setup ‘withOptions:AVAudioSessionCategoryOptionDuckOthers’ to minimise outside events from effecting background recording.

[ Testing Procedure ]

Only difference between Failure-CASE and Repeat-Failure-CASE is the screen-lock passcode was not required.

[ Notes ]

  1. Tested using XCode 6.1, on iPhone 4/5/6, iPad Mini 2 (iOS8.1) with same issue.
  2. Code is standard AVAudioRecorder code, with AVAudioSession setup similar to: http://www.jacopretorius.net/2013/04/record-and-playback-audio-in-ios.html

..

Hope the info helps, took a lot of trial and error to get to this point.

has anyone else experienced this issue? as its quite strange.

thanks

Upvotes: 3

Views: 504

Answers (1)

tigerose
tigerose

Reputation: 11

Your audio file(in sandbox) maybe is protected by iOS when passcode-lock; If the screen is locked without a passcode set, everything is ok;

Try the below:

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

Or,set your Data-protection in Certificate to close。

Upvotes: 1

Related Questions