Cocoa Application Finished Launch

后端 未结 1 545
温柔的废话
温柔的废话 2021-01-17 02:22

Is there any way to tell if a Cocoa application, such as Safari, has finished launching and able to respond? I know it\'s easy to do using delegates within the actual code b

1条回答
  •  野的像风
    2021-01-17 03:12

    Check out NSWorkspace and NSWorkspaceDidLaunchApplicationNotification. Something like this:

    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(appDidLaunch:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]
    

    The NSNotification object passed to the specified method will contain information about what application launched, its path, etc. For example:

    - (void)appDidLaunch:(NSNotification*)note
    {
        NSLog(@"app launched: %@", [note userInfo]);
    }
    

    EDIT: this is for desktop cocoa applications only - I'm fairly sure this is impossible in Cocoa Touch. Just clarifying that.

    0 讨论(0)
提交回复
热议问题