11
10

More than 5 years have passed since last update.

Mac OS Xでスリープ、復帰時の通知を扱う

Posted at

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");
}
11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10