当我尝试为 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,表明文件已经同步(或者我认为...)
所以,现在我继续进行以下调用以停止 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];
关于ios - 使用 setUbiquitous 为 UIDocument 文件关闭 iCloud 同步时出错(LibrarianErrorDomain 错误 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8548171/