1
A
回答
1
從官方文檔下面的代碼可以幫助你:
- (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];
}
欲瞭解更多信息,請參閱:https://developer.apple.com/library/mac/#qa/qa1340/_index.html
+0
感謝您的回答。不是我想要的。不告訴我如何檢測關機。我會搜索開發人員。 – yskywalker 2012-03-25 15:56:45
4
爲馬蒂亞斯提供,但更改通知的名稱爲
同一代碼:
NSWorkspaceWillPowerOffNotification
如果你要防止系統停機,請加
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
return NSTerminateCancel;
}
務必使用「NSApplicationDelegate」
好運!
相關問題
- 1. 檢測系統用戶關機
- 2. 使用Powershell檢測系統關機
- 3. Zend_Measure可以檢測公制系統嗎?
- 4. 如何檢查系統是否處於待機模式?
- 5. 從.NET Windows Service檢測系統待機/睡眠/休眠?
- 6. 可以Laravel Auth :: attempt()處理關係嗎?
- 7. 關係等待處理它的數據
- 8. 計算機科學「關於入侵檢測系統的知識」
- 9. 如何檢測Linux上掛起的系統關機?
- 10. 用於測試和提交待處理更改的系統(最好在Perforce中)
- 11. Windows操作系統關機事件處理
- 12. LaunchDaemon處理系統關閉 - 無SIGTERM?
- 13. 如何處理或檢測D中的系統信號?
- 14. 關係處理
- 15. jquery瀏覽器和操作系統檢測,可以檢測到android和iOs
- 16. 處理依賴關係並保持應用程序可插入
- 17. 不可預測的系統.DllNotFoundException
- 18. 是否可以檢測iPhone的Core或系統溫度?
- 19. Verilog中可合成'X'或無效輸入檢測系統
- 20. 在.NET中,我可以檢測系統焦點事件(C#)嗎?
- 21. 待定線性系統的隨機解
- 22. 我可以使用PHP檢測並處理MySQL警告嗎?
- 23. 檢測預處理器中的MOVBE可用性?
- 24. Jomsocial專業組件可以處理本地系統嗎?
- 25. 實時操作系統可以處理的進程數量
- 26. 多線程可以在單處理器系統上實現嗎?
- 27. 縮放圖像(可編寫腳本的圖像處理系統)
- 28. 安卓系統,可檢查菜單項
- 29. HOWTO區分系統關機
- 30. 檢查可用的處理核心
如果其中一位確實幫助解決了問題,請接受答案。這兩個答案結合在一起解決了你的問題。 – 2015-07-07 23:22:10