Instantly share code, notes, and snippets.

Embed
What would you like to do?
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