gpt4 book ai didi

ios - 使用 setUbiquitous 为 UIDocument 文件关闭 iCloud 同步时出错(LibrarianErrorDomain 错误 2)

转载 作者:行者123 更新时间:2023-11-29 11:18:04 25 4
gpt4 key购买 nike

当我尝试为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com