ICloud - sometimes renaming open documents on another device

Problem: I am working on an iCloud document on device A, for example. Ipod touch. Then I change the name of the document on device B, for example. my Mac (via Finder). The change goes into the cloud, and after device A pauses to know about it.

And then:

  • For a while, everything is just fine - I take away the name change using the changed property fileURLand can update my interface accordingly - the document continues to behave as it should
  • for a while, fileURL file returns as something like: file://localhost/var/mobile/Library/Mobile%20Documents/.ubd/peer-43A0AEB6-84CE-283E-CA39-FCC4EF3BC8F8-v23/ftr/purg-012fdcfbe3b3bbce6e603fdfd2f000b2cb28649e95No wonder this file will not be saved.

Can anyone explain what is happening and how it works?

Background

  • The name change is canceled by NSMetadataQuery. So, for example, I can rename documents that are not open, and all my iCloud functions work fine. The problem occurs only with open documents.

  • Other iCloud features work fine, for example. I can change the content on one device, for example. my Mac, and detect and then update my interface on another device, for example. my iPod Touch, which has a corresponding iCloud document.

  • , presentedItemDidMoveToURL: UIDocument. , , . . newURL URL- , - , , `lastPathComponent ', .. newURL - - "purg-", -012fdcfbe3b3bbce6e603fdfd2f000b2cb28649e95.

    - (void) presentedItemDidMoveToURL:(NSURL *) newURL;
    {   
        [super presentedItemDidMoveToURL: newURL];
    
        if ([(id)[self delegate] respondsToSelector:@selector(documentNameChanged:)])
        {
            [[self delegate] documentNameChanged: self];
        }
    }
    
  • presentedItemDidMoveToURL: . , , viewController, , fileURL , `purg-..... ". , .

al_lea, accommodatePresentedItemDeletionWithCompletionHandler:. al_lea, UIDocument. .

    - (void) accommodatePresentedItemDeletionWithCompletionHandler: (void (^) (NSError *errorOrNil)) completionHandler
    {    
        PresentedDocument* presentedDocument = [self retain];
        [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(), ^
        {
           [[NSNotificationCenter defaultCenter] postNotificationName: NOTIFY_presentedDocumentDeletedOnAnotherDevice
                                                               object: presentedDocument
                                                             userInfo: nil];

           [presentedDocument tidyUpAfterDelete];  // app specific tidy up
           [presentedDocument release];
       });
    }];
}

ItemDidMoveToURL: , , .

+5
1

URL , UIDocument :

file://localhost/var/mobile/Library/Mobile%20Documents/.ubd/peer-43A0AEB6-84CE-283E-CA39-FCC4EF3BC8F8-v23/ftr/purg-

, - NSFilePresenter accommodatePresentedItemDeletionWithCompletionHandler:

+6

All Articles