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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top