There is no predefined way of detecting if an observer has already been added for a particular NSNotification. So the best way to avoid adding multiple NSNotification observers is by explicitly calling removeObserver for the target / selector before adding it again. This way we can prevent duplicate observers from being added. The below method can be added as a category method
This assumes that the you will only add one unique observer to each target for any notification name, as it will remove any existing observers for that notification name.
@interface NSNotificationCenter (UniqueNotif)
- (void)addUniqueObserver:(id)observer selector:(SEL)selector name:(NSString *)name object:(id)object {
[[NSNotificationCenter defaultCenter] removeObserver:observer name:name object:object];
[[NSNotificationCenter defaultCenter] addObserver:observer selector:selector name:name object:object];
}
@end
This assumes that the you will only add one unique observer to each target for any notification name, as it will remove any existing observers for that notification name.