Question

When the user enables iCloud in my app, I need to move all local files to iCloud. Here, I use setUbiquitous:itemAtURL:destinationURL:error: to move each file. The problem is, if (for any local file) the same file URL already exists on iCloud, this method fails.

My question is, how can I determine which file is newer (local vs iCloud) so that I can either overwrite the iCloud version or discard the local version for each file? Or, could I somehow force iOS to perform the upload and set the file state into conflict on iCloud so that my conflict resolution methods would take over and handle this?

Was it helpful?

Solution

FWIW, from Apple's dox they suggest an all-or-nothing iCloud approach - i.e., ask the user at one point whether or not iCloud should be enabled or not and then don't change.

That said, for your situation I'd suggest the following steps after the user enables iCloud:

1) Run an NSMetaDataQuery with ubiquitous scope to get the list of files already in the cloud for this app. (Note that the query must be run on the main thread or you get nothing back).

2) If you have a file of the same name, you can use the last modified date key (NSMetadataItemFSContentChangeDateKey) in the NSMetaData to figure out which one you should use (or whatever approach you want to use for resolving the conflict)

3) If the file is not already in the cloud, then use the setUbiquitous method to put it there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top