I've found out, that I close the document 2 times and before closing it the 2nd time, I save it. I have remove the saveToURL method and now it works as expected.
For all who want to detect a deletion: Overwrite this method in your subclass of UIDocument with following code:
- (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];
});
}];
}
I hope this will help someone