For example, get the notification that another Application is becoming Active on the screen, or resign active state.
For example, get the notification that another Application is becoming Active on the screen,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sure. In your app delegate class, you can use
NSWorkspaceto get notified when an app becomes active (NSWorkspaceDidActivateApplicationNotification) or resigns active (NSWorkspaceDidDeactivateApplicationNotification). See the documentation onNSWorkspacefor more info.In your controller class, you’d do something like this:
The key points are basically that you need to register to receive the notifications like shown in
-init. You’d repeat the code to add another observer for each additional notification name that you want (e.gNSWorkspaceDidDeactivateApplicationNotification).Another important thing to remember is to remove yourself as an observer in
-dealloc(or elsewhere), so thatNSWorkspacedoesn’t try to notify your controller object after it’s been released+dealloc’d (and would no longer be valid).In the specified
-appDidActivate:method, do whatever you need to with the info about the app in question.