Receiving Workspace Notifications
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.
Receiving Workspace Notifications
Instead of going through the application’s default notification center as most notifications do, NSWorkspace
notifications are posted to a notification center provided by the NSWorkspace
object. 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; |
// Assume -observerMethod:(id)aNotification exists |
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter]; |
[notCenter addObserver:self |
selector:@selector(observerMethod:) |
name:nil object:nil]; // Register for all notifications |
Copyright © 2002, 2009 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2009-06-25