How to check if your iOS App comes into the foreground or background

I’ve been battling with those AppDelegate methods for a while, thinking “I wish there was a way that I don’t have to use those methods”. And guess what: there is!

Instead of adding code where it doesn’t make sense, we can listen to a system wide notification that tells us our app has come into the foreground, like so:

// observer checks if we're back from the background
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:UIApplicationWillEnterForegroundNotification object:nil];

Here the selector “myMethod” is called when our app is about to enter the foreground. Some of the interesting notifications are

  • UIApplicationDidEnterBackground
  • UIApplicationDidEnterForeground
  • UIApplicationWillTerminate

Find many more in Apple’s UIApplication Class Reference:

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at and