applicationDidEnterBackground()当应用进入后台时起作用
applicationWillTerminate()当应用终止的时候起作用
有了这两个方法,我们就可以对程序数据进行保护。
|
import
UIKit
@UIApplicationMain
class
AppDelegate
:
UIResponder
,
UIApplicationDelegate
{
var
window:
UIWindow
?
func
application(application:
UIApplication
didFinishLaunchingWithOptions launchOptions: [
NSObject
:
AnyObject
]?) ->
Bool
{
return
true
}
//当应用进入后台时其作用
applicationDidEnterBackground(application:
) {
saveData()
}
//当应用终止的时候起作用
applicationWillTerminate(application:
) {
saveData()
}
saveData(){
//获取导航控制器
let
navigation =
self
.window?.rootViewController
as
UINavigationController
//获取导航控制器的根视图控制器
controller:
ViewController
= navigation.viewControllers.first!
ViewController
controller.saveData()
}
applicationWillResignActive(application:
) {
}
applicationWillEnterForeground(application:
) {
}
applicationDidBecomeActive(application:
) {
}
}
|