2

I have a custom UIDocument subclass and implemented loadFromContents: and contentsForType:.

To detect that the document was changed on another device, I added a delegate to loadFromContents: as suggested in the Apple documentation:

- (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError **)outError {
    // load from disk […]

    if ([_delegate respondsToSelector:@selector(noteDocumentContentsUpdated:)]) {
        [_delegate noteDocumentContentsUpdated:self];
    }
    return YES;
}

My problem is that when I change the document on another device, I receive document state change notifications (edit_disabled followed by normal), but the contents are not reloaded and loadFromContents: is not called.

The contents definitely were updated on disk. When I manually reopen the document through the UI, I immediately see the latest changes.

Other times it works and loadFromContents: is called automatically. I can't figure out why it does not work sometimes. Has anybody else seen this problem?

Mark
  • 6,647
  • 1
  • 45
  • 88

1 Answers1

0

You may want to perform document version resolving manually after the notification and/or reload document after it become in normal state again.

Look at the following UIDocument method to simply reload document's content:

- (void)revertToContentsOfURL:(NSURL *)url completionHandler:(void (^)(BOOL success))completionHandler;
voromax
  • 3,369
  • 2
  • 30
  • 53