Monday, September 23, 2013

Application Delegate

Every iOS application must contain an application delegate object. Application Delegate class is responsible for handling all kind of events happen in the application. The root class is UIApplication. 

We do not subclass the UIApplication class to customize the handing of different kind of events, rather we provide an AppDelegate class that implements UIApplicationDelegate protocol. We provide this delegate class to the UIApplicaiton class which will sendd notifications to AppDelegate class for each of the application level event.

If you open up the AppDelegate.h class file and you will see the class declaration as

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;


This is the delegation class which implements the UIApplicationDelegate protocol. This class will receive messages from the Application class. 

Declaring the objects for UIWindow and viewController tells the compiler that these will be the objects holding the UI window and the ViewController class objects for this application.

@property is a generic way of declaring data that a class provides.

now if you open AppDelegate.m class in the editor you will see the implementation of the class. This is class implements the protocol methods and here are the methods you will see in this class.

  • (void)applicationWillResignActive:(UIApplication *)application 
  • (void)applicationDidEnterBackground:(UIApplication *)application 
  • (void)applicationWillEnterForeground:(UIApplication *)application
  • (void)applicationDidBecomeActive:(UIApplication *)application 
  • (void)applicationWillTerminate:(UIApplication *)application 

No comments:

Post a Comment