Created
January 19, 2014 04:45
-
-
Save yutopio/8500569 to your computer and use it in GitHub Desktop.
Sample project to inspect notification messages during iOS application running.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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