I'm developing a document-based app allowing users to draw UIBezierPaths. I rely on the UIDocument autosave feature, which is activated after a few seconds of no new data being added. However, I'm facing an issue:
When users force quit the app (swipe it away from the app switcher), large documents containing several thousand UIBezierPaths don't have sufficient time to save. The autosave only gets triggered if the document hasn't been edited for a few seconds. When the app enters the background and the document still has unsaved changes, I call the UIDocument save(to:for:completionHandler:). This function converts my UIBezierpath array to data (takes a few seconds if the array is large) and then stores it to the given url.
What is the recommended approach to ensure data integrity in such scenarios?
I attempted to use beginBackgroundTask(expirationHandler:), but it seems to be ineffective if the user force quits the app.