Objective-CでOS Xがスリープ、復帰するときの通知を受け取るには。
ここに書いてあった。
Registering and unregistering for sleep and wake notifications
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Setup system event notifications
[self fileNotifications];
}
- (void) fileNotifications
{
//These notifications are filed on NSWorkspace's notification center, not the default
// notification center. You will not receive sleep/wake notifications if you file
//with the default notification center.
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveSleepNote:)
name: NSWorkspaceWillSleepNotification object: nil];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveWakeNote:)
name: NSWorkspaceDidWakeNotification object: nil];
}
- (void) receiveSleepNote: (NSNotification*) note
{
NSLog(@"Sleep");
}
- (void) receiveWakeNote: (NSNotification*) note
{
NSLog(@"Awake");
}