Question

I am using SDK 10.8.

I am subclassing NSPersistentDocument (but the question might interest people sublassing NSDocument) and I want to deactivate the window restoration. So far, here is what I have done :

-(void)restoreStateWithCoder:(NSCoder *)coder
{
    NSLog(@"No 1") ;
}


-(void)restoreDocumentWindowWithIdentifier:(NSString *)identifier
                                     state:(NSCoder *)state
                         completionHandler:(void (^)(NSWindow *, NSError *))completionHandler
{
    NSLog(@"No 2") ;
}

The problem is that when I try in my application to create a new document, no window is shown.

What is the proper way to desactivate the window restoration ?

Was it helpful?

Solution

This function of window restoration makes my app unlaunchable, for instance after a crash (or I click stop in xcode). I don't want the users of my app to face the same problem and be unable to launch anymore the app.

That should only be true if your stored state is corrupt or you've changed the keys you store it under.

In normal circumstances, state restoration exists to save user data (that they haven't manually saved) in the event of a crash—your users will want it to be there when the app crashes on them.

For debugging purposes, you can disable state restoration in your Xcode scheme:

In Xcode 4's scheme editor, for the Run verb, on the Options tab, check the “Launch application without state restoration” checkbox.

OTHER TIPS

The following works, but I have to admit that I don't know why exactly !!

-(void)restoreDocumentWindowWithIdentifier:(NSString *)identifier
                                     state:(NSCoder *)state
                         completionHandler:(void (^)(NSWindow *, NSError *))completionHandler 
{
    DDLogWarn(@"Method 'restoreDocumentWindowWithIdentifier...' overidden") ;

    [[NSDocumentController sharedDocumentController] newDocument:nil] ;
}


- (void)restoreStateWithCoder:(NSCoder *)coder 
{
    DDLogWarn(@"Method 'restoreStateWithCoder...' overidden") ;

    [[NSDocumentController sharedDocumentController] newDocument:nil] ;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top