2014-02-18 4 views
1

나는이 같은 계층 구조로 QR 코드에 대한 검증이 필요 아이폰 OS 응용 프로그램을하고 있어요 AVCaptureSession을 중지하는 방법 : 제대로

View 
---Scan View 
---Image View - cardBG 
---Inside View 
  1. 보기를로드하는 경우, 스캔보기가 숨겨져

    .
  2. 사용자가 단추를 클릭하여 스캔하면 내부보기 및 이미지보기가 숨김으로 설정되어 스캔보기가 표시됩니다.
  3. 검색이 성공적으로 끝나면 인사이드 및 이미지가 다시 나타납니다.

문제는 단계 3에 있습니다. in this question과 같은 비동기 디스패치에서도 AVCaptureSession을 중지하면보기를 새로 고치는 데 8-10 초가 걸립니다.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    if([_captureSession isRunning])[_captureSession stopRunning]; 
    AVCaptureInput* input = [_captureSession.inputs objectAtIndex:0]; 
    [_captureSession removeInput:input]; 
    AVCaptureVideoDataOutput* output = (AVCaptureVideoDataOutput*)[_captureSession.outputs objectAtIndex:0]; 
    [_captureSession removeOutput:output]; 
}); 

[self.bgImageView setHidden:NO]; 
[self.insideView setHidden:NO]; 
[self.scanView setHidden:YES]; 
[self.previewLayer removeFromSuperlayer]; 

내 질문은 :이 동결을 피하려면 어떻게 볼 수 있습니까?

+0

당신이 http://stackoverflow.com/questions/3741121/how-to-properly-release이 스레드를 통해 답을 찾을 수 있습니다 -a-avcapturesession 고마워. –

답변

2

추가 컨텍스트 없이는 말하기 어렵습니다. 실제로 지연의 원인에 달려 있습니다. 이 작품이 좋아질까요?

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    if([_captureSession isRunning])[_captureSession stopRunning]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self.bgImageView setHidden:NO]; 
     [self.insideView setHidden:NO]; 
     [self.scanView setHidden:YES]; 
     [self.previewLayer removeFromSuperlayer];   
    }); 

    AVCaptureInput* input = [_captureSession.inputs objectAtIndex:0]; 
    [_captureSession removeInput:input]; 
    AVCaptureVideoDataOutput* output = (AVCaptureVideoDataOutput*)[_captureSession.outputs objectAtIndex:0]; 
    [_captureSession removeOutput:output];  

}); 
1

다음 코드는 당신을 도울 것입니다 :

if(self.previewLayer) { 
    [self.previewLayer removeFromSuperlayer]; 
    self.previewLayer = nil; 
} 

if(_captureSession) { 
    [_captureSession stopRunning]; 
    _captureSession = nil; 
} 
+0

감사합니다. 이것도 나를 도와줍니다. 이유는 UI를 업데이트하려고 할 때 메인 스레드가 아니 었습니다. – anhdat