Question

Is there any posible way to know if a Mac is in background or foreground?

In iOS we have the following methods: applicationWillEnterForeground applicationWillenterBackground

But is there any way to know if a Mac is active or inactive?

Was it helpful?

Solution

It depends on your application layout, but in general use an NSApplication delegate and implement:

- (void)applicationWillBecomeActive:(NSNotification *)aNotification

as well as its counterpart

- (void)applicationWillResignActive:(NSNotification *)aNotification

There are other notifications as well. See the linked document above. Also note that OS X allows real multitasking and thus background/foreground usually refer to having focus or not having focus.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top