I have an application based on NSDocument with an NSDocumentController subclass. My NSDocument works with both file URLs and URLs with a custom scheme which use a web service.
I handle much of the loading and saving using custom code, including -saveToURL:ofType:forSaveOperation:completionHandler:
. +autosavesInPlace
returns YES
.
The problem I'm having: documents with the custom URL scheme aren't restored on startup. Documents with the file URL scheme are – both regular documents saved to files, and untitled documents which are autosaved.
After leaving open server-based documents and quitting the app, no NSDocument methods appear to be called on restart. In particular, none of the four initializers is called:
- –init
- –initWithContentsOfURL:ofType:error:
- –initForURL:withContentsOfURL:ofType:error:
- –initWithType:error:
The NSDocumentController method -reopenDocumentForURL:withContentsOfURL:display:completionHandler:
is not called either.
How and when are documents' restorable state encoded? How and when are they decoded?
-encodeRestorableStateWithCoder:
. NSDocumentController uses that state information to restore the document, then invokes-makeWindowControllers
and NSApplication (or NSApplication's completion handler?) restores the window. Also, when using a custom subclass of NSDocumentController, AppKit sets that class as therestorationClass
. – Ruppert