Skip to content

Instantly share code, notes, and snippets.

@karnlund
Created February 28, 2017 18:52
Show Gist options
  • Select an option

  • Save karnlund/569bf915aefc24597129d64ed2a20a6a to your computer and use it in GitHub Desktop.

Select an option

Save karnlund/569bf915aefc24597129d64ed2a20a6a to your computer and use it in GitHub Desktop.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if defined( DEBUG )
[self dumpNotifications];
#endif
return YES;
}
- (void)dumpNotifications {
#define Debugger() { kill( getpid(), SIGINT ) ; }
NSNotificationCenter *notifyCenter = [NSNotificationCenter defaultCenter];
NSArray *ignoreList = @[@"_",
// ???
@"com.apple.pasteboard",
@"AXFrontBoard",
@"FABSettingsAvailableNotification",
@"kGTMSession",
// UIKit
@"NSBundle",
@"UIApplication",
@"UIDevice",
@"UIWindow",
@"UIView",
@"UIText",
@"UIStatusBar",
@"UIKeyboard",
@"UINavigationController",
// user defaults
@"NSUserDefaults",
// rendering?
@"BufferBacking",
@"PBDefault",
@"com.urbanairship",
@"CTRadioAccess",
// core data
@"NSPersistentStore",
@"NSObjectsChangedInManagingContextNotification",
@"NSManagingContext",
@"NSManagedObject",
@"NSSQL",
// Flurry?
@"FIRAScreen",
@"Flurry",
// GCD
@"NSThread"];
[notifyCenter addObserverForName:nil
object:nil
queue:nil
usingBlock:^(NSNotification *notification){
NSString *name = [notification name];
for (NSString *item in ignoreList) {
if ([name hasPrefix:item]) {
return;
}
}
// if ([name isEqualToString:@"NSThreadWillExitNotification"]) {
// Debugger()
// }
// Explore notification
NSLog(@"Notification found with:"
"\r\n name: %@"
"\r\n object: %@"
"\r\n userInfo: %@",
[notification name],
[notification object],
[notification userInfo]);
}];
}
@karnlund
Copy link
Author

Learn what notifications your app is really seeing by dumping all of them to the console!

This code has a configurable ignore list that you can easily customize to see as little or as much as you want. I'm certain you will learn about notifications that you never even knew existed to make better apps, like UIScreenBrightnessDidChangeNotification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment