AVCaptureSession - Stop Running - take a long long time

前端 未结 1 775
礼貌的吻别
礼貌的吻别 2021-01-03 11:53

I use ZXing for an app, this is mainly the same code than the ZXing original code except that I allow to scan several time in a row (ie., the ZXingWidgetController is not ne

相关标签:
1条回答
  • 2021-01-03 12:02

    According to the AV Cam View Controller Example calling startRunning or stopRunning does not return until the session completes the requested operation. Since you are sending these messages to the session on the main thread, it freezes all the UI until the requested operation completes. What I would recommend is that you wrap your calls in an Asynchronous dispatch so that the view does not lock-up.

    - (void)cancelled 
    {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [self stopCapture];
        });
    
       //You might want to think about putting the following in another method
       //and calling it when the stop capture method finishes
       wasCancelled = YES;
       if (delegate != nil) {
            [delegate zxingControllerDidCancel:self];
       }
    } 
    
    0 讨论(0)
提交回复
热议问题