是否可以有一个静态的 NSNotification 观察者(如下面的代码)?我遇到了一些问题,我认为这可能是由于我的单例类结构。
我并不总是有一个类实例来收听通知,但是这个类的静态属性在我的应用程序的生命周期中一直存在。
- (id)init {
[super init]
[[NSNotificationCenter defaultCenter] addObserver:[self class]
selector:@selector(action:aNotification:)
name:@"NSSomeNotification"
object:nil];
return self;
}
+ (void)action:(NSNotification *)aNotification {
NSLog( @"Performing action" );
}