Simple and safe way to observe notification
- Modify Facebook 's KVOController to work with NSNotificationCenter
- Example
self.notificationController = [FTGNotificationController controllerWithObserver:self];
[self.notificationController observeNotificationName:UIApplicationDidReceiveMemoryWarningNotification
object:nil
queue:[NSOperationQueue mainQueue]
block:^(NSNotification *note, id observer)
{
NSLog(@"observer %@ notification payload %@", observer, note);
}];
- To automatically remove observers on observer dealloc, declare FTGNotificationController as strong property
- Do not use self inside block as it causes retain cycle. Declare weak self or use observer parameter (declared as weak for you)
There are 2 ways
- Drag FTGNotificationController.h and .FTGNotificationController.m files to your project
- Using Cocoapods
pod 'FTGNotificationController'
or
pod 'FTGNotificationController', :git => 'https://github.com/onmyway133/FTGNotificationController.git'
- Use Kiwi/XCTest