Ios AvCamperView初始化缓慢,有时会在关闭/重新打开视图后导致崩溃-使用AVCam示例项目

Ios AvCamperView初始化缓慢,有时会在关闭/重新打开视图后导致崩溃-使用AVCam示例项目,ios,cocoa-touch,avcam,Ios,Cocoa Touch,Avcam,我正在使用AVCam示例项目,这是本月初(2014年2月)发布的最新版本。我已经添加了闪光灯选择功能并删除了录音功能,但我认为这与这个问题没有任何关系 更改视图并连续多次重新打开AVCam视图时,应用程序要么崩溃,要么需要很长时间才能初始化预览视图(约15秒)。这只是偶尔发生的 我假设该问题与更改视图时的清理有关,但该示例看起来是彻底清理: - (void)viewDidDisappear:(BOOL)animated { dispatch_async([self sessionQueue],

我正在使用AVCam示例项目,这是本月初(2014年2月)发布的最新版本。我已经添加了闪光灯选择功能并删除了录音功能,但我认为这与这个问题没有任何关系

更改视图并连续多次重新打开AVCam视图时,应用程序要么崩溃,要么需要很长时间才能初始化预览视图(约15秒)。这只是偶尔发生的

我假设该问题与更改视图时的清理有关,但该示例看起来是彻底清理:

- (void)viewDidDisappear:(BOOL)animated
{
dispatch_async([self sessionQueue], ^{
    [[self session] stopRunning];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceSubjectAreaDidChangeNotification object:[[self videoDeviceInput] device]];
        [[NSNotificationCenter defaultCenter] removeObserver:[self runtimeErrorHandlingObserver]];

        [self removeObserver:self forKeyPath:@"sessionRunningAndDeviceAuthorized" context:SessionRunningAndDeviceAuthorizedContext];
        [self removeObserver:self forKeyPath:@"stillImageOutput.capturingStillImage" context:CapturingStillImageContext];
        [self removeObserver:self forKeyPath:@"movieFileOutput.recording" context:RecordingContext];
    });
}
以下是我更改视图的代码(同时发送捕获的图像)(我正在使用故事板模式操作加载视图):

我不知道是什么导致了碰撞,也不知道为什么有时候相机预览需要15秒才能显示出来


提前感谢您的帮助

在[self session]stop running]之后,在viewdiddemouse方法中添加以下内容;为我解决了这个问题:

for(AVCaptureInput *input in captureSession.inputs) {
    [captureSession removeInput:input];
}

for(AVCaptureOutput *output in captureSession.outputs) {
    [captureSession removeOutput:output];
}
for(AVCaptureInput *input in captureSession.inputs) {
    [captureSession removeInput:input];
}

for(AVCaptureOutput *output in captureSession.outputs) {
    [captureSession removeOutput:output];
}