我发现,我关闭了文档 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];
});
}];
}
我希望这会对某人有所帮助