典型的NSNotificationCenter使用方法:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged)
name:kReachabilityChangedNotification
object:nil];
下面是官方的文档
SummaryAdds an entry to the notification center's dispatch table with an observer and a notification selector, and an optional notification name and sender. | ||||||||
Declaration- (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSNotificationName)aName object:(id)anObject; | ||||||||
DiscussionIf your app targets iOS 9.0 and later or macOS 10.11 and later, you don't need to unregister an observer in its dealloc method. Otherwise, you should call removeObserver:name:object: before | ||||||||
Parameters
|
意思是如果name,是nil那么,无论谁发送通知,都会调用这个selector。
参考文章:http://southpeak.github.io/2015/03/20/cocoa-foundation-nsnotificationcenter/