怎么在某个控制器中判断程序是否在前台或后台

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(appHasGoneInForeground:)
                                      name:UIApplicationWillEnterForegroundNotification
                                           object:nil];  
//别忘了删除监听
[[NSNotificationCenter defaultCenter] removeObserver:self];   


UIApplicationDidEnterBackgroundNotification  //进入后台
UIApplicationWillEnterForegroundNotification //回到程序
原文地址:https://www.cnblogs.com/pangbin/p/5411959.html