5
A
回答
7
只是覺得:
- (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(receiveWakeNote:)
name: NSWorkspaceDidWakeNotification object: NULL];
}
2
您可以使用IORegisterForSystemPower()。
連接呼叫者根電源域的IOService,用於接收系統休眠喚醒&通知的目的 。 不提供系統關閉和重新啓動通知。
io_connect_t IORegisterForSystemPower (
void *refcon,
IONotificationPortRef *thePortRef,
IOServiceInterestCallback callback,
io_object_t *notifier) ;
2
爲SWIFT 3:
func onWakeNote(note: NSNotification) {
print("Received wake note: \(note.name)")
}
func onSleepNote(note: NSNotification) {
print("Received sleep note: \(note.name)")
}
func fileNotifications() {
NSWorkspace.shared().notificationCenter.addObserver(
self, selector: #selector(onWakeNote(note:)),
name: Notification.Name.NSWorkspaceDidWake, object: nil)
NSWorkspace.shared().notificationCenter.addObserver(
self, selector: #selector(onSleepNote(note:)),
name: Notification.Name.NSWorkspaceWillSleep, object: nil)
}
相關問題
- 1. 當程序運行時發生事件時會發生什麼
- 2. 從回收站中恢復某個項目時會觸發什麼事件
- 3. 當MKMAPVIEW範圍發生變化時會觸發什麼事件
- 4. 當在Mac OS X中使用「\ r \ n」時會發生什麼?
- 5. 當UISlider拖到最後時會發生什麼事件?
- 6. 當UIView被解僱時會發生什麼事件?
- 7. 當我選擇工作表時會發生什麼事件?
- 8. 當我多次訂閱Timer.Elapsed事件時會發生什麼?
- 9. 從墓碑狀態恢復後會發生什麼?
- 10. 當ARIES算法的恢復階段DBMS崩潰時會發生什麼?
- 11. 會發生什麼事時,使用make_shared
- 12. 當一個定時器線程進入睡眠狀態時會發生什麼
- 13. 當localStorage已滿時會發生什麼?
- 14. 當redis重載時會發生什麼?
- 15. 當我ping 127.0.0.1時會發生什麼
- 16. 當FlatFileFooterCallback出錯時會發生什麼?
- 17. 當AsyncTasks已滿時會發生什麼?
- 18. 當crontabs重疊時會發生什麼?
- 19. 當EditText有空時會發生什麼?
- 20. 當VRAM已滿時會發生什麼?
- 21. 當我編譯時會發生什麼?
- 22. 爲什麼LostFocus事件不會發生?
- 23. 爲什麼事件DOMContentReady不會發生?
- 24. Gridview的OnDataBound事件會發生什麼?
- 25. Git階段和提交 - 恢復時未提交的文件會發生什麼?
- 26. 當一個事件從一個任務中被觸發時會發生什麼?它會有單獨的線程?
- 27. 當沒有任何事情發生時,Akka會做什麼?
- 28. 當發生javascript運行時錯誤時會發生什麼?
- 29. 當輸入字段的值發生變化時會觸發什麼事件?
- 30. 當我從SQL遊標中返回時會發生什麼?
兩件事情:你想要的 「無」 不是 「NULL」 爲你的對象,你應該格式化你的答案是將你的代碼顯示爲格式化的代碼 - 現在它很難讀。但很好的回答你自己的問題! – 2012-02-12 09:39:50
如何正確格式化代碼?我不知道所需的標籤...謝謝! – 2012-02-12 13:08:06
看起來像帕拉格擊敗你。但是在將來,請查看編輯器中的按鈕。其中之一是一對大括號(「{}」)。使用它將選定的文本塊格式化爲代碼。 – 2012-02-12 18:18:18