第一步:
建立2個NSNotificationCenter監聽app
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil]; //監聽是否觸發home鍵掛起程序.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil]; //監聽是否從新進入程序程序.
第二步:
實現2個NSNotificationCenter所觸發的事件方法ui
- (void)applicationWillResignActive:(NSNotification *)notification
{
printf("按理說是觸發home按下\n");
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
printf("按理說是從新進來後響應\n");
}
注: 在home鍵觸發後,AppDelegate響應的方法爲:this
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers,
spa
and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
rest