1、在AppDelegate中
//進(jìn)入后臺(tái)的時(shí)候調(diào)用
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
NSLog(@"進(jìn)入后臺(tái)");
}
//從后臺(tái)進(jìn)入的時(shí)候調(diào)用
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
NSLog(@"回到app");
}
2撒璧、使用通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hadEnterBackGround) UIApplicationDidEnterBackgroundNotification object:nil];
- (void)hadEnterBackGround{
NSLog(@"進(jìn)入后臺(tái)");
}
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hadEnterForeGround) name:UIApplicationDidBecomeActiveNotification object:nil];
- (void)hadEnterForeGround{
NSLog(@"回到app");
}