سؤال

How can I print every single notification on my system in obj-C?

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

what does in "..."? Should I use NSDistributedNotificationCenter?

let's say I have a function called logfunc which will do NSLog(@"ok");

thank you

هل كانت مفيدة؟

المحلول

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

You can then define a method that matches your selector, like this:

- (void)myMethod:(NSNotification *)notification {
    NSLog(@"notification received: %@", notification);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top