What is an AppDelegate?

Recently I needed to call an external process after an iPhone app I have been working on finished loading uploading tracking information to a web server.

The way to do this is by creating a custom class and then calling that _NAME_AppDelegate.m file within your code, but what is an AppDelegate?

The AppDelegate just sits there doing nothing, waiting to be told that something potentially important has or will happen. The application/iPhone OS is the one doing the work and calling the AppDelegate when it has or will do something that the AppDelegate (and by extension, you) might want to respond to in your code.

Here is a complete scenario:

(Starting at the iPhone’s home screen)
1. A user taps on your app’s icon.
2. The iPhone OS loads your app into memory and whatever else it needs to run your app. At this point, the OS has control.
3. The iPhone OS finishes its launch procedure with your app, and is ready to hand over control to it.
4. The OS calls your AppDelegate’s applicationDidFinishLaunching method.
5. Your code is now in control, starting with whatever is in the applicationDidFinishLaunching method of your AppDelegate.
. (User uses the app for a while)
6. User taps on the Home button to quit your app.
7. Since your app has no direct way of knowing when the Home button is tapped, the iPhone OS sends an applicationWillTerminate message to your AppDelegate, so you can clean up any open files, etc. before the app quits.

There are also other notifications that your AppDelegate can receive between launching and quitting, such as if your app is about to run out of memory.