読者です 読者をやめる 読者になる 読者になる

Cocoa API解説(macOS/iOS)

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。

目次

NSWorkspaceDidHideApplicationNotification

INDEX>AppKit>NSWorkspace

アプリケーションが隠された時の通知

解説

アプリケーションが隠された時の通知

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.6-

更新時のバージョン

OS X 10.10.3
Swift1.2

参照

関連記事(外部サイト)

例文

Objective-C

Swift

    //NSWorkspace NSWorkspaceSessionDidBecomeActiveNotification
    //NSWorkspace NSWorkspaceSessionDidResignActiveNotification
    //NSWorkspace NSWorkspaceDidHideApplicationNotification
    var switch050 : Bool = false
    func notify050(notify:NSNotification) {
        //NSLog("!! %@",notify.description)
        
        if notify.name == NSWorkspaceSessionDidBecomeActiveNotification {
            NSLog("NSWorkspaceSessionDidBecomeActiveNotification")
        }
        
        if notify.name == NSWorkspaceDidHideApplicationNotification {
            let runningApp : NSRunningApplication = (notify.userInfo! as Dictionary)["NSWorkspaceApplicationKey"]! as! NSRunningApplication
            NSLog("runningApp = %@",runningApp.description)
            // ->runningApp = <NSRunningApplication: 0x600000105340 (com.apple.mail - 36867)>
            NSLog("runningApp = %@",runningApp.launchDate!.description)
            // ->runningApp = 2015-04-29 09:18:27 +0000
        }
    }
    @IBAction func function050(sender: AnyObject) {
        let notificationName1 : String = NSWorkspaceSessionDidBecomeActiveNotification
        let notificationName2 : String = NSWorkspaceSessionDidResignActiveNotification
        let notificationName3 : String = NSWorkspaceDidHideApplicationNotification
        let notificationSelector : Selector = Selector("notify050:")
        
        if switch050 {
            //通知の監視をやめる
            NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self,
                name: notificationName1, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self,
                name: notificationName2, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self,
                name: notificationName3, object: nil )
            NSLog("--------observe off")
            switch050 = false
            
        }else{
            //通知の監視を始める
            NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,
                selector: notificationSelector, name: notificationName1, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,
                selector: notificationSelector, name: notificationName2, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,
                selector: notificationSelector, name: notificationName3, object: nil )
            NSLog("--------observe on")
            switch050 = true
        }
    }