O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Examining the Different Application States

The iOS includes events that you can handle in your application delegate so that you can monitor your application's current state. The following Try It Out shows the various states that an application goes through.

TRY IT OUT: Handling Application Event States

image

  1. Using Xcode, create a Single View Application (iPhone) project and name it States. You will also use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Add the following bold code to the StatesAppDelegate.m file:
    #import “StatesAppDelegate.h”
    
    #import “StatesViewController.h”
    
    @implementation StatesAppDelegate
    
    @synthesize window = _window;
    @synthesize viewController = _viewController;
    
    - (BOOL)application:(UIApplication *)application
          didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       NSLog(@“application:didFinishLaunchingWithOptions:”);
       self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
         autorelease];
       // Override point for customization after application launch.
       self.viewController = [[[StatesViewController alloc]
         initWithNibName:@“StatesViewController” bundle:nil] autorelease];
       self.window.rootViewController = self.viewController;
       [self.window makeKeyAndVisible];
       return YES;
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application
    {
        NSLog(@“applicationWillResignActive:”); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required