标签:
1. APPDelegate中的代理方法可以监听到程序前后台切换的状态
- (void)applicationDidEnterBackground:(UIApplication * )application { NSLog(@"---applicationDidEnterBackground----") // 进入后台 } - (void)applicationDidBecomeActive:(UIApplication * )application { NSLog(@"---applicationDidBecomeActive----") // 进入前台 } - (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"---applicationDidEnterBackground----") // 进入后台 } - (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"---applicationDidBecomeActive----") // 进入前台 }
2. 单个ViewController通过在ViewDidLoad里注册筛选器通知来监听,在dealloc中移除通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod1:) name:UIApplicationDidBecomeActiveNotification object:nil];
标签:
原文地址:http://www.cnblogs.com/clumsy1006/p/5303635.html