func saveAndCloseWithCompletionHandler(_ onCompletion :((Bool) -> Void)?)
{
self.prepareForClosing();
self.saveDocument { (saveSuccess) in
if(saveSuccess) {
self.closeDocument(completionHandler: { (_) in
onCompletion?(saveSuccess);
});
}
else {
onCompletion?(saveSuccess);
}
}
}
func prepareForClosing() {
#if !NS2_SIRI_APP
//save local meta data cache
self.localCacheWrapper?.saveMetadataCache();
self.deleteUnusedFileItems();
#endif
}
func saveDocument(completionHandler : ((Bool) -> Void)?)
{
if(self.openPurpose == .read) {
completionHandler?(true);
return;
}
if(self.hasAnyUnsavedChanges) {
(self.delegate as? FTNoteshelfDocumentDelegate)?.documentWillStartSaving(self);
}
#if !NS2_SIRI_APP
self.recognitionCache?.saveRecognitionInfoToDisk(forcibly: true);
if(self.hasAnyUnsavedChanges) {
if let cache = self.recognitionCache, let cachePlist = cache.recognitionCachePlist() {
let mutableDict = NSMutableDictionary.init(dictionary: cachePlist.contentDictionary);
self.recognitionInfoPlist()?.updateContent(mutableDict);
}
if let cache = self.recognitionCache, let cachePlist = cache.visionRecognitionCachePlist() {
let mutableDict = NSMutableDictionary.init(dictionary: cachePlist.contentDictionary);
self.visionRecognitionInfoPlist()?.updateContent(mutableDict);
}
//This was added in version 6.2, when we removed the bounding rect from the Segment level storage.
updateDocumentVersionToLatest()
}
#endif
super.save { (success) in
if(success) {
self.previousFileModeificationDate = self.fileModificationDate;
let pages = self.pages();
for eachPage in pages {
eachPage.isDirty = false;
}
}
completionHandler?(success);
}
}
func closeDocument(completionHandler: ((Bool) -> Void)?)
{
#if !NS2_SIRI_APP
self.recognitionCache?.saveRecognitionInfoToDisk(forcibly: true)
#endif
super.close { (success) in
self.removeObservers();
completionHandler?(success);
}
}
// in above function, super is --> UIDocument
Topic:
Programming Languages
SubTopic:
Swift
Tags: