Graphics Programs Reference
In-Depth Information
For The More Curious: Application State Transitions
Let's write some quick code to get a better understanding of the different application state
transitions.
You already know about
self
, an implicit variable that points to the instance that is ex-
ecuting the current method. There is another implicit variable called
_cmd
, which is the se-
lector for the current method. You can get the
NSString
representation of a selector with
the function
NSStringFromSelector
.
In
HomepwnerAppDelegate.m
, implement the application state transition delegate
methods so that they print out the name of the method. You'll need to add four more meth-
ods. (Check to make sure the template hasn't already created these methods before writing
brand new ones.)
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"%@", NSStringFromSelector(_cmd));
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"%@", NSStringFromSelector(_cmd));
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"%@", NSStringFromSelector(_cmd));
}
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"%@", NSStringFromSelector(_cmd));
}
Now, add the following
NSLog
statements to the top of
applica-
tion:didFinishLaunchingWithOptions:
and
applicationDidEnter-
Background:
.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"%@", NSStringFromSelector(_cmd));
...
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{