コンピュータがココアでシャットダウンしようとしていることを検出するにはどうすればよいですか?インターネット上に何もないように見える。これは、シャットダウンとログアウトを区別する必要があります。コカコーラによる保留中のシステムシャットダウンの検出
誰でも私にこれを手伝ってもらえますか?
コンピュータがココアでシャットダウンしようとしていることを検出するにはどうすればよいですか?インターネット上に何もないように見える。これは、シャットダウンとログアウトを区別する必要があります。コカコーラによる保留中のシステムシャットダウンの検出
誰でも私にこれを手伝ってもらえますか?
公式ドキュメントから次のコードは、あなたを助けることがあります。詳細については
- (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
答えをありがとう。しかし、私が望んでいたものではなかった。シャットダウンを検出する方法を教えてくれません。私は開発者を検索します。 – yskywalker
同じコード:
NSWorkspaceWillPowerOffNotification
システムのシャットダウンを防ぎたい、「NSApplicationDelegate」
幸運を使用することを確認し
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
return NSTerminateCancel;
}
を追加してください!
問題の解決に役立った回答があれば受け入れてください。あなたの問題を解決した2つの答えが結合されました。 –