Meeting the iOS App Methods and Platforms

Part of the Beginning iOS Programming For Dummies Cheat Sheet

When writing an iOS app, it's very important to understand and weave app-specific code into its lifecycle. Trying to figure out which lifecycle method to use? Check this list:

  • Use willFinishLaunchingWithOptions to do any processing right after the app starts up and before it displays its first window, and before it even has a restored state.

    You typically use this method to check whether the startup parameters to the app (such as a URL) are correct. You could also check the environment in which the app is launched (for example, did it launch on an iPad that has the ability to make cellular calls). Incidentally, this method will not work on a device with an iOS version older than iOS 6.

  • Use didFinishLaunchingWithOptions to do any processing after you’re sure that the app is going to start.

    For example, you can use this method to restore a global state.

  • Use applicationDidBecomeActive in order to restart a process that was paused while the app was inactive.

    For example, you could start to listen for location changes or even refresh the UI with fresh data.

  • Use applicationWillResignActive to pause your app while the user gives his attention to another activity — such as answering a phone call.

  • Use applicationDidEnterBackground to release resources and save user data along with enough app state information to restore your app to its current state in case it's terminated later.

    You are allowed approximately five seconds of processing in this method, so don’t do any tasks that may not terminate — such as prompting the user.

  • Use applicationWillEnterForeground to undo what you did in applicationDidEnterBackground.

  • Use applicationWillTerminate to do any final cleanup tasks.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus

SERIES
Beginning iOS Programming For Dummies Cheat Sheet

Advertisement

Inside Dummies.com