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----")
// 进入前台
}
单个ViewController通过在ViewDidLoad里注册筛选器通知来监听,在dealloc中移除通知
//监听是否重新进入程序程序.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(someMethod1:)
name:UIApplicationDidBecomeActiveNotification object:nil];
//监听是否触发home键挂起程序.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];