I've attempted to prevent my app from doing any OpenGL in the background, but it's still getting killed occasionally out in the field, and I haven't been able to reproduce it yet.
The OpenGL use is for rendering document thumbnails.
Definitively, where should OpenGL be started and stopped?
Apple's docs are seemingly inconsistent. In the OpenGL ES Programming Guide for iOS, we have:
In your app’s applicationWillEnterForeground: method, re-create any objects and restart your animation timer.
And in the App Programming Guide for iOS, we have:
Apps that use OpenGL ES for drawing must not use these methods to prepare their drawing environment. Instead, defer any OpenGL ES drawing calls to the applicationDidBecomeActive: method.
Apparently, applicationWillEnterForeground
is called before applicationDidBecomeActive
. That wold mean that starting animation in applicationWillEnterForeground
would not defer drawing calls to applicationDidBecomeActive
.
Currently, I'm doing the following:
- Start thumbnail rendering in
applicationDidBecomeActive
andapplicationWillEnterForeground
- Stop thumbnail rendering in
applicationWillResignActive
per documentation.
I'm using an OperationQueue
for thumbnail rendering and do the following to stop the queue:
func stopQueue() {
// Ensure all operations are finished so we don't
// call OpenGL while the app is backgrounded.
workerQueue.waitUntilAllOperationsAreFinished()
workerQueue.isSuspended = true
}