Getting notified when the current application changes in Cocoa

前端 未结 2 484
青春惊慌失措
青春惊慌失措 2020-12-23 18:33

I want to be notified when the current application will change. I looked at NSWorkspace. It will send notifications only when your own application becomes active or loses th

2条回答
  •  生来不讨喜
    2020-12-23 18:46

    If you're targeting 10.6 or later there's a notification for this:

    // NSWorkspaceDidActivateApplicationNotification
    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(foremostAppActivated:) name:NSWorkspaceDidActivateApplicationNotification object:nil];
    

    Apple docs: http://developer.apple.com/library/mac/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/doc/uid/20000391-SW97

提交回复
热议问题