如何在OBJ-C中打印系统上的每个通知?

[[NSNotificationCenter defaultCenter] addObserver:self ...];

在“ ...”中有什么?我应该使用nsdistributednotificationcenter吗?

假设我有一个称为logFunc的函数,该函数将执行nslog(@ok ok”);

谢谢你

有帮助吗?

解决方案

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:nil object:nil];

然后,您可以定义与选择器相匹配的方法,例如:

- (void)myMethod:(NSNotification *)notification {
    NSLog(@"notification received: %@", notification);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top