When do UIManagedDocuments close?

I use this blog: http://www.adevelopingstory.com/blog/2012/03/core-data-with-a-single-shared-uimanageddocument.html to create a singleton for a singlet UIManagedDocument. Here is the relevant code inBetterDatabase

//In BetterDatabase

typedef void (^OnDocumentReady) (UIManagedDocument *document);

- (void)performWithDocument:(OnDocumentReady)onDocumentReady
{
    void (^OnDocumentDidLoad)(BOOL) = ^(BOOL success) {
        onDocumentReady(self.document);
    };

    if (![[NSFileManager defaultManager] fileExistsAtPath:[self.document.fileURL path]]) {
        [self.document saveToURL:self.document.fileURL
                forSaveOperation:UIDocumentSaveForCreating
               completionHandler:OnDocumentDidLoad];
    } else if (self.document.documentState == UIDocumentStateClosed) {
        [self.document openWithCompletionHandler:OnDocumentDidLoad];
    } else if (self.document.documentState == UIDocumentStateNormal) {
        OnDocumentDidLoad(YES);
    }
}

//In other class
[[BetterDatabase sharedDocumentHandler] performWithDocument:^(UIManagedDocument * document) {
        //Do stuff 1
        //Do stuff 2
}];

My question is: When can I close a UIManagedDocument automatically? Namely, is it possible to close a document (OS / SDK) between lines 1 and 2? What if the user minimizes the application for the iPhone, and then opens it again? Does it close UIManagedDocument?

Another way to express it: Will it UIManagedDocumentever close while I still have a strong pointer to it?

+5
source share
1

: UIManagedDocument? : " iOS ". , , ( , ). .

, AppDelegate

- (void)applicationWillResignActive:(UIApplication *)application

( , UIManagedDoc)

UIManagedDocument, , " UIDocumentStateChangedNotification"

: . : , . UIManagedDocument, , , .

stuff1 stuff2 - , - .

, , . Apple , . UIManagedDocument, .

, , - - , - .

, , , ( , ?), - UIManagedDocument , .

EDIT: , , . , , , , . , , , , . Apple DataSource, , ( , , ..).

,

- (void)objectsDidChange:(NSNotification *)notification
{
#ifdef DEBUG
    NSLog(@"NSManagedObjects did change.");
#endif
}

- (void)contextDidSave:(NSNotification *)notification
{
#ifdef DEBUG
    NSLog(@"NSManagedContext did save.");
#endif
}

, , :

userInfo = {
    inserted = "{<the Core data fields inserted>}";
    updated = "{<code data fields updated>}";
}}

. , , . , ..

UIManagedDoc , .

!

+4

All Articles