La vista previa de AVCam se atasca después de desbloquear el teléfono

Estamos desarrollando una aplicación de camera ios que tiene funciones como: captura de image / video, gestión de files multimedia, compartir files multimedia, etc. Nuestra pantalla de inicio es la pantalla de vista previa de la camera. Esto tiene muchos botones para navegar a otras pantallas.

Si estamos en la pantalla del visor y luego bloqueamos y desbloqueamos el teléfono, la vista previa permanece en Aceptar. Pero si navego desde el visor a otra pantalla y vuelvo al visor, luego hago un locking y deslocking, la vista previa de la camera se atasca, es decir, la pantalla mostrará el último fotogtwig. Pero los botones, etc. son navegables. Este es el error que estamos recibiendo:

Capture session runtime error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x1490838e0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}, NSLocalizedFailureReason=An unknown error occurnetworking (-12780), NSLocalizedDescription=The operation could not be completed 

¿Cuál es la forma más estable y eficiente de ver la vista previa?

Algunos fragments de código relevantes:

  -(void) setGUIBasedOnMode{ if (![self isStreamStarted]) { if (shutterActionMode == SapCamSelectionModeLiveStream) { _flashButton.hidden = true; _cameraButton.hidden = true; _liveSteamSession = [[VCSimpleSession alloc] initWithVideoSize:[[UIScreen mainScreen]bounds].size frameRate:30 bitrate:1000000 useInterfaceOrientation:YES]; [_liveSteamSession.previewView removeFromSuperview]; AVCaptureVideoPreviewLayer *ptr; [_liveSteamSession getCameraPreviewLayer:(&ptr)]; _liveSteamSession.previewView.frame = self.view.bounds; _liveSteamSession.delegate = self; } else{ [_liveSteamSession.previewView removeFromSuperview]; _liveSteamSession.delegate = nil; // [self removeObservers]; _cameraButton.hidden = false; if(flashFlag == 0){ _flashButton.hidden = false; } else if(flashFlag == 1){ _flashButton.hidden = true; } self.session = [[AVCaptureSession alloc] init]; self.previewView.hidden = false; self.previewView.session = self.session; [self configureCameraSettings]; dispatch_async( self.sessionQueue, ^{ switch ( self.setupResult ) { case AVCamSetupResultSuccess: { [self addObservers]; [self.session startRunning]; self.sessionRunning = self.session.isRunning; if(loadingCameraFlag == false){ [self hidingView]; } break; } case AVCamSetupResultCameraNotAuthorized: { dispatch_async( dispatch_get_main_queue(), ^{ NSString *message = NSLocalizedString( @"App doesn't have permission to use the camera, please change privacy settings", @"Alert message when the user has denied access to the camera"); UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"AVCam" message:message prefernetworkingStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"OK", @"Alert OK button" ) style:UIAlertActionStyleCancel handler:nil]; [alertController addAction:cancelAction]; UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"Settings", @"Alert button to open Settings" ) style:UIAlertActionStyleDefault handler:^( UIAlertAction *action ) { [[UIApplication shanetworkingApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; }]; [alertController addAction:settingsAction]; [self presentViewController:alertController animated:YES completion:nil]; } ); break; } case AVCamSetupResultSessionConfigurationFailed: { dispatch_async( dispatch_get_main_queue(), ^{ NSString *message = NSLocalizedString( @"Unable to capture media", @"Alert message when something goes wrong during capture session configuration" ); UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"OK", @"Alert OK button" ) style:UIAlertActionStyleCancel handler:nil]; [alertController addAction:cancelAction]; [self presentViewController:alertController animated:YES completion:nil]; } ); break; } } }); } } } 

Más:

 [self.session beginConfiguration]; if ( [self.session canAddInput:videoDeviceInput] ) { [self.session addInput:videoDeviceInput]; self.videoDeviceInput = videoDeviceInput; dispatch_async( dispatch_get_main_queue(), ^{ UIInterfaceOrientation statusBarOrientation = [UIApplication shanetworkingApplication].statusBarOrientation; AVCaptureVideoOrientation initialVideoOrientation = AVCaptureVideoOrientationPortrait; if ( statusBarOrientation != UIInterfaceOrientationUnknown ) { initialVideoOrientation = (AVCaptureVideoOrientation)statusBarOrientation; } AVCaptureVideoPreviewLayer *previewLayer = (AVCaptureVideoPreviewLayer *)self.previewView.layer; previewLayer.connection.videoOrientation = initialVideoOrientation; } ); } else { self.setupResult = AVCamSetupResultSessionConfigurationFailed; }