标签: nsdistributednotification

如何使用Swift 3检测macOS默认模式和黑暗模式之间的切换

我想在用户从默认模式切换到黑暗模式时更改状态栏应用程序图标,反之亦然(使用Swift 3).这是我到目前为止所拥有的:

func applicationDidFinishLaunching(_ aNotification: Notification) {
    DistributedNotificationCenter.default().addObserver(self, selector: #selector(darkModeChanged(sender:)), name: "AppleInterfaceThemeChangedNotification", object: nil)
}

...

func darkModeChanged(sender: NSNotification) {
    print("mode changed")
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,它没有用.我究竟做错了什么?

observers selector nsnotificationcenter swift nsdistributednotification

6
推荐指数
1
解决办法
1927
查看次数