1 經過AppDelegate 實現ios
App進入後臺事件方法app
- (void)applicationDidEnterBackground:(UIApplication *)applicationspa
APP進入前臺的事件方法server
- (void)applicationWillEnterForeground:(UIApplication *)application事件
2UIViewController類中經過對Background ,Foreground事件的通知的偵聽,進行實現rem
舉例string
- (void) viewWillAppear:(BOOL)animated{ io
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForegroundNotification) name:UIApplicationWillEnterForegroundNotification object:nil]; event
} class
- (void) appWillEnterForegroundNotification{
NSLog(@"trigger event when will enter foreground.");
}
-(void) viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
注意:在UIViewController類中viewDidUnload方法在ios6之後過時失效