几个状态的切换
application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:
applicationWillResignActive:
applicationDidEnterBackground:
applicationWillEnterForeground:
applicationWillTerminate:
可以重写
- (void)applicationDidEnterBackground:(UIApplication *)application {
//home键时执行直接退出程序
[[UIApplication sharedApplication] terminateWithSuccess];
}
但terminateWithSuccess是一个私有的方法,appstore的审核是通不过的,还有种方法是把terminateWithSuccess换成“exit(0);”,这行代码也是可以实现按home键退出程序的功能,而且能通过审核。
http://www.cocoachina.com/bbs/simple/?t40614.html
可以看看: applicationWillEnterForeground 或 applicationDidEnterBackground 或 applicationWillResignActive 等是否合用。
2.keyWindow
This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.
3.实现了UIApplicationDelegate的AppDelegate类中的dealloc 方法存在一个奇怪的地方:
这个方法不会被调用!任何在 AppDelegate 的 dealloc 方法中设置的断点都不起作用!这是正常的。当iOS 关闭一个程序时,它只是简单的把内存清空,以加快关闭的速度。这也是为什么 AppDelegate 的 dealloc 方法中的任何代码都不会被运行。
不需要手动调用 dealloc 方法以“解决这个问题”。如果你确实需要在程序关闭之前在 AppDelegate 中运行代码,你可以在 applicationWillTerminate 方法中运行代码。如果你的目标 iOS 是 4 或者更高的版本,你应该使用applicationDidEnterBackground。
4.