iOS GPUImage自定义相机锁屏后崩溃

      前段时间用GPUImage自定义了相机,但是测试发现在相机界面,锁屏后再打开,程序崩溃,全局断点每次都崩溃到下面这个代码段

- (void)presentBufferForDisplay;

{

[self.context presentRenderbuffer:GL_RENDERBUFFER];

}

搜索之后发现,GPUImage是基于OpenGL 的,而OpenGL ES在进入后台后是直接退出的,在stack上发现了类似的问题,在GPUImage的issue 197得到了解决方法,注册通知监听程序进入后台(UIApplicationWillResignActiveNotification)和进入前台(UIApplicationDidBecomeActiveNotification),通过下面方法即可解决相机界面进入后台崩溃的问题。

- (void)goToBack

{

  [self.stillCamera pauseCameraCapture];

  [self.stillCamera stopCameraCapture];

  runSynchronouslyOnVideoProcessingQueue(^{

      glFinish();

});

}

- (void)gotoFore

{

[self.stillCamera resumeCameraCapture];

[self.stillCamera startCameraCapture];

}

你可能感兴趣的:(iOS GPUImage自定义相机锁屏后崩溃)