【发布时间】:2019-03-28 06:22:55
【问题描述】:
我在 iOS 中使用 (AVFoundation) AVCapture Session 实现了一个 QR 阅读器。在我的 ParentViewController 中,我实现了一个 CollectionView。在 collection view cell 内我已经实现了 QR 码阅读器 并且我开始捕获会话开始在单元内运行。它工作正常并读取元数据输出。当元数据输出委托调用时,我停止会话。但是如果我离开 ParentView 控制器,捕获会话仍在运行,当我导航到另一个 ViewController 时,它会从后台捕获会话。为什么会这样?当导航到另一个视图控制器时,如何停止捕获会话。
这是层次结构,
ParentViewController --->(inside)CollectionView --->(inside) CollectionViewCell --->(inside) QR Reader with capture session Strat.
会发生什么,
ParentViewController ----> (navigate to another controller) Capture Session Still Activated and reads qr codes from background
我想要什么,
ParentViewController ---->(navigate to another controller) Shouldn't capture anything.
我在 ParentViewController 中尝试过,在 viewWillDisappear 里面
override open func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
let qrreaderCell = QRReaderCell()
qrreaderCell.captureSession.stopRunning()
ColletionView.reloadItems(at: [IndexPath(row: 0, section: 0)])
}
但没有工作并且失败了。任何人都可以帮助解决这个问题。
【问题讨论】:
标签: ios swift avfoundation avcapturesession