Questioner
Questioner

Reputation: 31

iOS: programmatically prevent iCloud backup

How can I programmatically prevent a file in my Documents directory from being backed up to iCloud if the user has enabled that? I assume there are two routes: backed up from the iOS device and backed up from the iTunes backup on the Mac. I see that people recommend using setxaddr to prevent backup to the Mac, but what about preventing iOS from automatically sending a file's contents to iCloud?

Upvotes: 2

Views: 1654

Answers (2)

MRR
MRR

Reputation: 31

https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/PerformanceTips/PerformanceTips.html#//apple_ref/doc/uid/TP40007072-CH7-SW17

https://developer.apple.com/library/archive/qa/qa1719/_index.html

Check these links. Hope it guides you resolve the matter at hand.

In iOS 5.1 and later, store support files in the /Library/Application Support directory and add the NSURLIsExcludedFromBackupKey attribute to the corresponding NSURL object using the setResourceValue:forKey:error: method. (If you are using Core Foundation, add the kCFURLIsExcludedFromBackupKey key to your CFURLRef object using the CFURLSetResourcePropertyForKey function.) Applying this attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.

Upvotes: 1

matt
matt

Reputation: 535851

Example:

var myFileURL = // file URL
var rv = URLResourceValues()
rv.isExcludedFromBackup = true
try? myFileURL.setResourceValues(rv)

Upvotes: 3

Related Questions