在 OSX 上检测监视器更改

Detecting monitor changes on OSX

我有一个应用程序要求有关监视器更改的通知以便重新配置,如果我添加监视器,这些目前不会被触发:

    [[NSDistributedNotificationCenter defaultCenter] addObserver:self
                                                        selector:@selector(distNotificationHook:)
                                                            name:NSApplicationDidChangeScreenParametersNotification
                                                          object:nil];


    [[NSDistributedNotificationCenter defaultCenter] addObserver:self
                                                        selector:@selector(distNotificationHook:)
                                                            name:@"com.apple.BezelServices.BMDisplayHWReconfiguredEvent"
                                                          object:nil];

他们曾经工作过..但现在不工作了。有人看到我在这里做错了什么吗?

原来问题是这个需要使用NSNotificationCenter,而不是NSDistributedNotificationCenter:

  [[NSNotificationCenter defaultCenter] addObserver:self
                                                        selector:@selector(distNotificationHook:)
                                                            name:@"com.apple.BezelServices.BMDisplayHWReconfiguredEvent"
                                                          object:nil];