【问题标题】:crash removing keyValue observer (using Apple SquareCam example code)删除 keyValue 观察者时崩溃(使用 Apple SquareCam 示例代码)
【发布时间】:2012-05-01 21:16:01
【问题描述】:

我正在使用 Apple 的 SquareCam 演示中的 viewController 类。除了创建一个 UIView 之外,我没有更改代码,该示例在示例中是通过情节提要/IB 设置的。还要在构建设置中指定要从 ARC 中排除。

代码使用 KVO 做一些动画我在下面的 removeObserver 行上遇到了崩溃。

我可以轻松解决这个问题而不使用 KVO,但我想了解这个问题 - 并且更好地了解 KVO。有时代码示例中的 KVO 很难遵循。例如:在下面的 sn-ps 中,addObserver/removeObservercalls 的 keyPaths 是不同的(在 Apple 的代码中)。他们不应该一样吗?

无论如何...如果有人有 X 光视力

- (void)teardownAVCapture
{
[videoDataOutput release];
if (videoDataOutputQueue)
    dispatch_release(videoDataOutputQueue);

    // CRASH HERE
[stillImageOutput removeObserver:self forKeyPath:@"isCapturingStillImage"];

[stillImageOutput release];
[previewLayer removeFromSuperlayer];
[previewLayer release];
}

// 这里设置了观察者:

    stillImageOutput = [AVCaptureStillImageOutput new];
[stillImageOutput addObserver:self forKeyPath:@"capturingStillImage" options:NSKeyValueObservingOptionNew context:AVCaptureStillImageIsCapturingStillImageContext];

【问题讨论】:

    标签: ios ios5 key-value-observing


    【解决方案1】:

    我在尝试重拍时也遇到了这个问题,我的临时解决方案是rem that code

    [stillImageOutput removeObserver:self forKeyPath:@"isCapturingStillImage"];
    

    并尝试调用

    [session stopRunning]
    

    【讨论】:

    • 您的代码不要使用 >,而是使用 4 个空格。您的代码将突出显示。
    【解决方案2】:

    我将其视为 SquareCam 中的一个错字并使用:

    [stillImageOutput removeObserver:self forKeyPath:@"capturingStillImage"];
    

    【讨论】:

      【解决方案3】:

      如果我没记错的话

      isCapturingStillImage 和 capturingStillImage 值应该匹配。

      如果应用找不到匹配的观察者,它就会崩溃..

      希望这会有所帮助..

      【讨论】:

      • 是的,除非他们正在观察多个项目......然后他需要添加和删除两者。
      • 我只是仔细检查了 Apple 网站的来源,但名称不匹配 - 因此我感到困惑。这可能是他们的错误 - 或者他们正在做更多我错过/没有在这里发布的事情。 developer.apple.com/library/ios/#samplecode/SquareCam/Listings/…
      • 我有同样的崩溃问题。你有什么更新吗?我们是否需要为 isCapturingStillImage 和 captureStillImage 保留不同的字符串?
      猜你喜欢
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多