Skip to content

Instantly share code, notes, and snippets.

@yutopio
Created January 19, 2014 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutopio/8500569 to your computer and use it in GitHub Desktop.
Save yutopio/8500569 to your computer and use it in GitHub Desktop.
Sample project to inspect notification messages during iOS application running.
//
// YTONotificationTest.m
//
// Created by Yuto Takei on 1/19/14.
// Copyright (c) 2014 Yuto Takei. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
@interface NotificationTestViewController : UIViewController
@end
@implementation NotificationTestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Add observer");
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(changedAssets:)
name:NULL
object:NULL];
[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(sendNotification)
userInfo:nil
repeats:NO];
}
- (void)sendNotification
{
NSNotification *notif = [NSNotification notificationWithName:@"Foobar"
object:self
userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotification:notif];
}
- (void)dealloc
{
NSLog(@"Remove observer");
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)changedAssets:(NSNotification *)notification
{
NSLog(@"Received notiication: %@", [notification name]);
}
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[NotificationTestViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
@end
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment