In iOS, I'm trying to do multiple (upwards of 10) screen snapshots (UIImages) per second to be combined into a video and am running into some challenges.
UIView's drawHierarchy seems to be to slow when run on the main thread, causing jitter with the UI experience. I've noticed that I can run it on a background thread, but only when passing a value of FALSE for the afterScreenUpdates parameter. This does cause the main thread warning to be written to the console (when the main thread checker is turned off), but does work. And I don't have to worry about blocking the main thread as it is on a background thread.
The question is, will running drawHierarchy on the background thread potentially cause memory corruption when traversing the entire tree of a UIWindow.
And if so, what is the advised most performant method of capturing iOS screenshots?
drawHierarchy Doc: https://developer.apple.com/documentation/uikit/uiview/1622589-drawhierarchy
TIA
We cannot guarantee correctness or stability using UIView APIs from a secondary thread.
Capturing pixels like this in real time is generally not recommended in cases where performance is critical – APIs like ReplayKit use hardware blocks that can do this in a way that won't impact the user experience as much.