Stepping through the App Life Cycle

Although simple for the eventual user, the birth, life, and death of an application is a pretty complex process. In this section, I explain what happens throughout the time that the user launches the app from the Home screen, uses the app, and then stops using the app, either because she is done or decides to respond to an interruption such as an SMS message.

The life of an iPad app begins when a user launches it by tapping its icon on the Home screen. The system launches your app by calling its main function — which Xcode kindly lets you peek at if you go to the Project navigator, open the disclosure triangle next to the Supporting Files group, and select main.m.

tip.eps The details of the implementation shown here may change, but the overall architecture will stay the same from iOS version to iOS version.

#import <UIKit/UIKit.h>

#import “RTAppDelegate.h”

int main(int argc, char *argv[])

{

@autoreleasepool {

return UIApplicationMain(argc, argv, nil, NSStringFromClass([RTAppDelegate class]));

}

}

The main function is where a program starts execution. This function is responsible for the high-level organization of the program’s functionality and typically has access to the arguments given to the program when it gets executed.

The main function does only these two things:

1. Sets up an autorelease pool:

@autoreleasepool {

This is a piece of memory-management ...

Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.