iOS忽略enqueueSampleBuffer,因为状态失败

当我从这里重新启动应用程序: https : //github.com/zweigraf/face-landmarking-ios相机的图片不会出现,并打印错误:“忽略enqueueSampleBuffer,因为状态失败”。

这个问题可能是在SessionHandler.swift的captureOutput中

我find一个解决scheme! 感谢为什么AVSampleBufferDisplayLayer失败,操作中断(-11847)?

如果你有类似的问题,你需要设置AVSampleBufferDisplayLayer每次应用程序进入前景。 喜欢这个:

//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() }