iOS iCloud documents: can I prevent documents from being purged?

251 Views Asked by At

I have an app that stores documents in iCloud. iOS seems to regularly purge the local copies of the ubiquitous documents, forcing my users to re-download from iCloud. I had assumed this was due to low storage on the devices but I’ve experienced it myself when my device has more than 3GB of free space.

I also see the same behaviour in the Apple Books app. On the other hand in the Apple TV app on the same device, purchased movies I download don’t ever seem to be automatically purged. This has been the case for me since around the launch of iOS 13, but some of my users have complained of the issue on earlier iOS versions.

Is there a flag I’m missing somewhere that would prevent iOS from purging my documents? The biggest these files get is around 5MB.

Edit based on following Warren Burton's link: After reading the document at https://developer.apple.com/icloud/documentation/data-storage/ , I'm wondering if what I'm looking for is the "do not back up" attribute. I'd previously interpreted this as meaning that if a user reinstalled from a backup, all my app's documents would be lost. But if documents are stored in iCloud, I suppose they would still be available in the same way after a backup is restored, so they don't actually need to be in the user's backup? To further add to my confusion, the docs at https://developer.apple.com/documentation/foundation/urlresourcekey/1408756-isexcludedfrombackupkey specifically say not to use this attribute on user documents, so maybe this isn't the right attribute. Can anyone clarify?

1

There are 1 best solutions below

0
On

I’ve come to the conclusion that there’s no way to get the behaviour I want by just relying on the iCloud file management itself.

What I’m going to attempt to do is to copy files manually from the ubiquity container to the local documents and work with them there, saving back to the ubiquity container as necessary. It seems a bit inelegant but should get the experience I want.