简体   繁体   中英

Application Reopen Event - Cocoa/ObjectiveC

I have application1 calling application2 using

[[NSWorkspace sharedWorkspace] launchApplicationAtURL:....

Now, when Application2 opens, I want to do some operation on windows load. This is fine when I open the application first time. I can do my logic in awakeFromNib event.

If the application 2 is minimized (In dock) after open, it opens from the doc when application1 calls application2 again and none of initWithWindow, awakeFromNib, WindowDidLoad is triggering.

Is there any window event which gets triggered when opened from first time or reopen from minimized state?

As an NSApplication delegate you will receive various notifications/calls you can use for that. For example could you use

- (void)applicationDidBecomeActive:(NSNotification *)aNotification
- (void)applicationDidResignActive:(NSNotification *)aNotification

You may only have to check first start vs. becoming active using a variable in your app delegate. Also, DidBecomeActive should be called also on startup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM