static void registerForDriverLoadedNotification()
{
// Snipped code that works and is not related to issue
}
static void registerForApplicationChangedNotification()
{
NSLog(@"registerForApplicationChangedNotification!");
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserverForName: nil object: nil queue: nil
usingBlock: ^(NSNotification* notification) {
NSLog(@"NOTIFICATION %@ -> %@", notification.name,
notification.userInfo);
}];
}
int main (int argc, const char* argv[]) {
registerForDriverLoadedNotification();
registerForApplicationChangedNotification();
CFRunLoopRun();
return 0;
}上面的代码是用于守护进程的,它等待USB设备插入,然后加载配置。我希望扩展此功能,以检测何时启动应用程序,以及是否存在特定于应用程序的配置,加载该功能。
但是,除了NSUserDefaultsDidChangeNotification之外,我似乎没有收到任何其他通知。
registerForApplicationChangedNotification中的代码最初是监视NSWorkspaceDidActivateApplicationNotification和NSWorkspaceDidDeactivateApplicationNotification,但我将其更改为catch-all,这样我就可以看到发布了哪些其他通知。
不管发生什么,似乎只收到了NSUserDefaultsDidChangeNotification通知.这段相当简单的代码有什么问题?
发布于 2015-07-26 06:36:43
愚蠢的错误!
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
应:
NSNotificationCenter* center = [[NSWorkspace sharedWorkspace] notificationCenter]
https://stackoverflow.com/questions/31634279
复制相似问题