Database Reference
In-Depth Information
DLog(@
"UIDocumentStateClosed %@"
, notification);
break
;
case
UIDocumentStateInConflict:
DLog(@
"UIDocumentStateInConflict %@"
, notification);
break
;
case
UIDocumentStateSavingError:
DLog(@
"UIDocumentStateSavingError %@"
, notification);
break
;
case
UIDocumentStateEditingDisabled:
DLog(@
"UIDocumentStateEditingDisabled %@"
, notification);
break
;
}
}
From the state of the
UIManagedDocument
, we can update our user interface to
reflect that state and let the user know what is going on with the underlying
data.
Manually Saving a UIManagedDocument
By default, the
UIManagedDocument
works to ensure that our data is saved as
frequently as makes sense.
The
UIDocument
design knows to listen for
UIApplicationWillResignActiveNotification
,
UIApplicationDidEnterBackgroundNotification
, and
UIApplicationWillTerminateNotification
notifi-
cations. When it receives one of these notifications, it saves. It also saves
periodically during the life of the application. On average, these periodical
saves take place every five minutes.
However, we know our application better than the frameworks do. We know
when something nonrecoverable or vital has just occurred, and we can decide
that a save is mandatory at a specific point. Fortunately, it is possible to
convey that need to
UIManagedDocument
.
NSURL *fileURL = [[self managedDocument] fileURL];
[[self managedDocument] saveToURL:fileURL
forSaveOperation:UIDocumentSaveForCreating
completionHandler:^(BOOL success) {
//Handle failure
}];
The call to request a save is the same we used when we were initially creating
the
UIManagedDocument
. Further, we can request the URL for the save directly
from the
UIManagedDocument
. The only detail left is planning how to properly
respond to a failed save.