Grabación de voz en segundo plano utilizando AVAudioRecorder
Estoy tratando de grabar la voz del usuario en segundo plano usandoAVAudioRecorder
pero cada vez que tengoNO
mientras llamarecordForDuration
método. Agrego "audio" aUIBackgroundModes
Pero esto no ayuda. Por cierto, todo funciona perfecto en primer plano. Estoy inicializandoAVAudioRecorder
usando este código:
NSError* error;
if (![[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:&error])
{
NSLog(@"Error while setting audio session category. Code - %d, description - \"%@\".", [error code], [error localizedDescription]);
return;
}
NSURL* outputFileURL = [VKMFileSystemHelper uniqueFileInPath:[[VKMFileSystemHelper subdirectoryInsideLibrary:DIR_AUDIO] path] withExtension:@"m4a"];
NSDictionary* recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt:AVAudioQualityMin] , AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16] , AVEncoderBitRateKey,
[NSNumber numberWithInt:1] , AVNumberOfChannelsKey,
[NSNumber numberWithFloat:12000.0] , AVSampleRateKey,
nil];
_recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSettings error:&error];
[_recorder setDelegate:self];
if (error)
{
NSLog(@"Error occured during audio recorder initialization. Error code - %d, description - \"%@\".", [error code], [error localizedDescription]);
}
else
{
NSLog(@"Start recording.");
if ([_recorder recordForDuration:[shedule execLength]])
{
NSLog(@"Record started.");
}
else
{
NSLog(@"Record failed.");
}
}
¿Cómo puedo grabar desde el micrófono desde el fondo? es posible?