user88975
user88975

Reputation: 1648

How to detect if app is inactive in mac application

I need to display alerts in the app, and if app is inactive I need to use NSUserNotification to send out alerts else I will use a simple sheetModal alert dialog. How can I know if the application is active or inactive ? i.e user is actively using the app or using some other app ?

I need to replicate same alert system as in Xcode, if Xcode is active it shows a message on Xcode window else it will post a UserNotification.

Upvotes: 2

Views: 966

Answers (2)

markhunte
markhunte

Reputation: 6932

You should read the Docs on NSApplicaion.

In it you will see

isActive

Returns a Boolean value indicating whether this is the active application.

- (BOOL)isActive
Return Value
YES if this is the active application; NO otherwise.

Upvotes: 2

Jay
Jay

Reputation: 6638

How about applicationWillResignActive::

Sent by the default notification center immediately before the application is deactivated.

Check out Apple's documentation on the NSApplicationDelegate protocol.

Upvotes: 2

Related Questions