I'm having some trouble implementing NSWindowRestoration
(in 10.7 Lion). I'm not getting the protocol notifications.
Is there an example app with this implemented somewhere? I cannot find one on the Apple Developer site. Thanks!
Edit: The question marked as answer is helpful, but the problem in my case was that I was using a menubar-only application. I guess window restoration doesn't work with dockless apps yet. Snap!
The class method + (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler
as described by "El Developer" is only half of the solution.
The class that implements the method (and conforms to the NSWindowRegistration protocol) also has to be registered as the window's "Restoration Class".
When the window is initially created, register it using the - (void)setRestorationClass:(Class <NSWindowRestoration>)restorationClass
method.
e.g. for a window controller, for initialization:
_myWindowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"];
_myWindowController.window.restorationClass = self.class;
_myWindowController.window.identifier = @"MyWindow";
for restoration:
+ (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler {
if ([identifier isEqualToString:@"MyWindow"]) {
MyAppDelegate *appDelegate = (MyAppDelegate *)NSApplication.sharedApplication.delegate;
NSWindow *myWindow = appDelegate.myWindowController.window;
completionHandler(myWindow, nil);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With