尝试关闭UIDocument文件的iCloud同步时遇到错误。想知道是否有人遇到了这个问题。这是场景:
我在应用程序沙箱中本地创建了一个UIDocument文件,然后进行以下调用以开始与iCloud同步文件:
[[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:localPathURL destinationURL:cloudPathURL error:&error];
一切进展顺利。
现在,我想停止该文件的iCloud同步。
我首先通过调用以下命令来确保文件至少已与iCloud同步:
- (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;
}
上面的返回YES,表明文件已经同步(或者我认为...)
因此,现在我继续进行以下 call ,以停止iCloud对此文件的同步:
[[NSFileManager defaultManager] setUbiquitous:NO itemAtURL:localPathURL destinationURL:cloudPathURL error:&error];
并且出现以下错误:“操作无法完成。(LibrarianErrorDomain错误2-无法禁用未同步项目的同步。)”
知道为什么会发生此错误以及如何消除它吗?我本以为我的文件已完全同步...
提前致谢!
最佳答案
我想到了。要禁用iCloud同步,我不小心拨打了电话:
[[NSFileManager defaultManager] setUbiquitous:NO itemAtURL:localPathURL destinationURL:cloudPathURL error:&error];
代替
[[NSFileManager defaultManager] setUbiquitous:NO itemAtURL:cloudPathURL destinationURL:localPathURL error:&error];