静的な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" );
}