nsdistributednotification

How to detect switch between macOS default & dark mode using Swift 3

眉间皱痕 提交于 2020-01-13 09:40:07
问题 I want to change my status bar app icon when the user switches from default to dark mode and vice versa (using Swift 3). Here’s what i have so far: func applicationDidFinishLaunching(_ aNotification: Notification) { DistributedNotificationCenter.default().addObserver(self, selector: #selector(darkModeChanged(sender:)), name: "AppleInterfaceThemeChangedNotification", object: nil) } ... func darkModeChanged(sender: NSNotification) { print("mode changed") } Unfortunately, it’s not working. What

How to detect switch between macOS default & dark mode using Swift 3

有些话、适合烂在心里 提交于 2019-12-05 07:54:49
I want to change my status bar app icon when the user switches from default to dark mode and vice versa (using Swift 3). Here’s what i have so far: func applicationDidFinishLaunching(_ aNotification: Notification) { DistributedNotificationCenter.default().addObserver(self, selector: #selector(darkModeChanged(sender:)), name: "AppleInterfaceThemeChangedNotification", object: nil) } ... func darkModeChanged(sender: NSNotification) { print("mode changed") } Unfortunately, it’s not working. What am I doing wrong? I'm using this Swift 3 syntax successfully: DistributedNotificationCenter.default