2012-03-22 11 views
1

コンピュータがココアでシャットダウンしようとしていることを検出するにはどうすればよいですか?インターネット上に何もないように見える。これは、シャットダウンとログアウトを区別する必要があります。コカコーラによる保留中のシステムシャットダウンの検出

誰でも私にこれを手伝ってもらえますか?

+0

問題の解決に役立った回答があれば受け入れてください。あなたの問題を解決した2つの答えが結合されました。 –

答えて

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

4
マティアスが提供する、しかしに通知の名前を変更するよう

同じコード:

NSWorkspaceWillPowerOffNotification

システムのシャットダウンを防ぎたい、「NSApplicationDelegate」

幸運を使用することを確認し

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender 
{ 
    return NSTerminateCancel; 
} 

を追加してください!

関連する問題