Workspace notifications are posted when:
applications are launched and terminated
volumes are mounted or unmounted
the Finder performs file operations
the Finder becomes the active application or resigns as the active application
the user logs out or shuts down the computer
the computer wakes from sleep.
NSWorkspace notifications are posted to a notification center
provided by the NSWorkspace object, instead of going through the
application’s default notification center as most notifications
do. To receive NSWorkspace notifications, your application must register
an observer with the NSWorkspace notification center, returned by
the notificationCenter
method.
The code fragment in Listing 1 registers a method observerMethod
with
the NSWorkspace notification center to receive all NSWorkspace notifications:
Listing 1 Registering for workspace notifications
NSNotificationCenter *notCenter; |
SEL observerMethodSEL; |
// Assume -observerMethod:(id)aNotification exists |
observerMethodSEL = @selector(observerMethod:); |
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter]; |
[notCenter addObserver:self selector:observerMethodSEL |
name:nil object:nil]; // Register for all notifications |
© 2002, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-03-06)