gpt4 book ai didi

ios - 使用 iCloud 正确处理应用程序另一个实例中的 UIDocument 删除

转载 作者:行者123 更新时间:2023-11-28 22:37:48 25 4
gpt4 key购买 nike

我发现,我可以通过以下方法检测 iCloud 上 UIDocument 的删除:

- (void)accommodatePresentedItemDeletionWithCompletionHandler:(void (^)(NSError *))completionHandler

此方法被正确调用,但我不知道在该方法中要做什么。在我关闭文档的那一刻,如果它仍然打开,但看起来文档在关闭时保存在旧路径上,所以文档重新出现。

我已经进行了大量搜索,但在 Apple 文档和任何论坛中都没有找到任何内容。

有没有人有过类似的经历,或者有没有人正确处理过删除?

最佳答案

我发现,我关闭了文档 2 次,在第二次关闭之前,我保存了它。我删除了 saveToURL 方法,现在它按预期工作。

对于所有想要检测删除的人:使用以下代码在您的 UIDocument 子类中覆盖此方法:

    - (void)accommodatePresentedItemDeletionWithCompletionHandler:(void (^)(NSError *errorOrNil))completionHandler
{
sceneLampDocument* presentedDocument = self;
[presentedDocument closeWithCompletionHandler: ^(BOOL success) {
NSError* error = nil;
if (!success)
{
NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not close document that is being deleted on another device",
NSLocalizedDescriptionKey, nil];
error = [NSError errorWithDomain: @"some_suitable_domain"
code: 101
userInfo: userInfo];
}

completionHandler(error); // run the passed in completion handler (required)

dispatch_async(dispatch_get_main_queue(), ^
{
//[super accommodatePresentedItemDeletionWithCompletionHandler:completionHandler];

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:self forKey:@"document"];
[[NSNotificationCenter defaultCenter] postNotificationName: @"documentDeletedOnAnotherDevice"
object: self
userInfo: userInfo];
});
}];
}

我希望这对某人有帮助

关于ios - 使用 iCloud 正确处理应用程序另一个实例中的 UIDocument 删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15403818/

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