//页面将要进入前台,开启定时器
-(void)viewWillAppear:(BOOL)animated
{
//注册程序进入前台通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (startTimer) name: UIApplicationWillEnterForegroundNotification object:nil];
//注册程序进入后台通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (pauseTimer) name: UIApplicationDidEnterBackgroundNotification object:nil];
[super viewWillAppear:animated];
}
/**
* 这个方法里移除通知
*/
-(void) viewWillDisappear:(BOOL)animated {
//解除程序进入前台通知
[[NSNotificationCenter defaultCenter] removeObserver:self name: UIApplicationWillEnterForegroundNotification object:nil];
//解除程序进入后台通知
[[NSNotificationCenter defaultCenter] removeObserver:self name: UIApplicationDidEnterBackgroundNotification object:nil];
[super viewWillDisappear:animated];
}