I am running into an error when I try to turn iCloud sync off for a UIDocument file. Wondering if anyone else has run into this. Here’s the scenario:
I create a UIDocument file locally in the app sandbox and then make the following call to begin syncing the file with iCloud:
[[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:localPathURL destinationURL:cloudPathURL error:&error];
Everything’s going swimmingly.
Now I want to stop iCloud syncing for this file.
I first make sure that the file has at least been synced with iCloud by calling the following:
- (BOOL) isDataFileSyncedWithCloud
{
if (![self isICloudSupported] || ![self isUsingICloudForFiles])
return NO;
NSURL* file = [self getFileURLToCloudDatafile];
NSNumber* isInCloudNum = nil;
if ([file getResourceValue:&isInCloudNum forKey:NSURLIsUbiquitousItemKey error:nil])
{
// If the item is in iCloud, see if it is downloaded and uploaded.
if ([isInCloudNum boolValue])
{
NSNumber* isDownloadedNum = nil;
if ([file getResourceValue:&isDownloadedNum forKey:NSURLUbiquitousItemIsDownloadedKey error:nil])
{
NSNumber* isUploadedNum = nil;
if ([file getResourceValue:&isUploadedNum forKey:NSURLUbiquitousItemIsUploadedKey error:nil])
{
return ([isDownloadedNum boolValue] && [isUploadedNum boolValue]);
}
}
}
}
return NO;
}
The above returns YES, indicating the file has been synced (or so I thought…)
So, now I go ahead and make the call below to stop iCloud syncing for this file:
[[NSFileManager defaultManager] setUbiquitous:NO itemAtURL:localPathURL destinationURL:cloudPathURL error:&error];
and I get the following error: “The operation couldn’t be completed. (LibrarianErrorDomain error 2 – Cannot disable syncing on a unsynced item.)”
Any idea why this error is occurring and how I can get rid of it? I would have thought that my file was fully synced…
Thanks in advance!
I figured it out. To disable iCloud syncing, I was accidentally calling:
instead of