I have an already running enterprise application which stores a lot of documents inside the documents folders. I wish to disable the iCloud backup of all these documents and folders inside the Documents folder.
The problem is that the contents inside the folder keep on changing dynamically and the idea of adding
kCFURLIsExcludedFromBackupKey
for every files sounds a bit difficult, as there are multiple classes in my code which can write to the documents directory.
Is there any way I can disable the upload of the entire documents folder and its subfolder.
You can put
kCFURLIsExcludedFromBackupKey
(orNSURLIsExcludedFromBackupKey
) to the entire Documents directory just like you would for a single file. However, if you don't want any of the files backed up, you may want to rethink where they should go. The Documents directory is for user data only. If files are stored on your own servers, they should probably go inCaches
because they can be downloaded again easily. If the files are only needed for a short period of time, they should go intmp/
.This is Apple's documentation about where to put your app's files.
Perhaps the files are changing dynamically because they are being regularly updated from a server or similar? If so, then the answer is to move your file storage from the
<Application_Home>/Documents
directory to the<Application_Home>/Library/Caches
directory. These documents will not be backed up. This is of course only suitable if the data can be re-downloaded or recreated in the future, if required.See this Apple documentation for an overview: https://developer.apple.com/icloud/documentation/data-storage/index.html
You can call these once at first install. And it will apply on subfolders and files.
In appDelegate of your application in the following method
Add this code