











1 通过AppDelegate 实现
App进入后台事件方法
- (void)applicationDidEnterBackground:(UIApplication *)application
APP进入前台的事件方法
- (void)applicationWillEnterForeground:(UIApplication *)application
2UIViewController类中通过对Background ,Foreground事件的通知的侦听,进行实现
举例
- (void) viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForegroundNotification) name:UIApplicationWillEnterForegroundNotification object:nil];
}
- (void) appWillEnterForegroundNotification{
NSLog(@"trigger event when will enter foreground.");
}
-(void) viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
注意:在UIViewController类中viewDidUnload方法在ios6以后过期失效
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。