本文介绍了iOS忽略enqueueSampleBuffer,因为状态失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从此处重新启动应用程序时: https://github.com/zweigraf/face-相机中的地标性iOS 图片未出现,并且出现打印错误:由于状态失败而忽略enqueueSampleBuffer".

When I restart app from here: https://github.com/zweigraf/face-landmarking-ios picture from camera doesn't appear and printing error: "Ignoring enqueueSampleBuffer because status is failed".

问题可能出在SessionHandler.swift的captureOutput中

The problem is probably in captureOutput from SessionHandler.swift

推荐答案

我找到了解决方案!感谢为什么AVSampleBufferDisplayLayer会因操作中断(-11847)而失败? a>

I find a solution! Thanks to Why does AVSampleBufferDisplayLayer fail with Operation Interrupted (-11847)?

如果您遇到类似的问题,则每次应用进入前台时都需要设置AVSampleBufferDisplayLayer.像这样:

If you had similar problem you need to set AVSampleBufferDisplayLayer each time app entering foreground. Like this:

//AppDelegate.swift
func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

    viewcontroller?.setLayer()
}


//ViewController.swift
func setLayer() {
    sessionHandler.layer = AVSampleBufferDisplayLayer()
    sessionHandler.layer.frame = preview.bounds
    sessionHandler.layer.videoGravity = AVLayerVideoGravityResizeAspectFill
    preview.layer.addSublayer(sessionHandler.layer)
}

不要忘记删除子层:

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    viewcontroller?.sessionHandler.layer.removeFromSuperlayer()
}

这篇关于iOS忽略enqueueSampleBuffer,因为状态失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!