COCOA에서 sleep, wake up 이벤트 처리
196 hit since 2008/11/11 10:09
코코아 어플에서 MAC OS X이 sleep에 들어가는지, sleep에서 빠져나왔는지를 확인하는 방법이다. Workspace의 notification center에 observer를 등록하는 방식으로 구현이 된다.
- - (void) receiveSleepNote: (NSNotification*) note
{
NSLog(@"receiveSleepNote: %@", [note name]);
}
- (void) receiveWakeNote: (NSNotification*) note
{
NSLog(@"receiveSleepNote: %@", [note name]);
}
- (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: NULL];
- [[[NSWorkspace sharedWorkspace] notificationCenter]
- addObserver: self
- selector: @selector(receiveWakeNote:)
- name:NSWorkspaceDidWakeNotification object: NULL];
- }
fileNotification 함수를 호출하여 sleep, wakeup 이벤트에 대해서 observer를 등록해두면, OS가 sleep에 들어갈 때, wake up 할 때 어플리케이션에서 알 수 있게된다.
* 더 자세한 내용은 아래 링크 참조.
http://developer.apple.com/qa/qa2004/qa1340.html


Trackback (0)
Comment (0)