class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 监听是否重新进入App
NotificationCenter.default.addObserver(self, selector: #selector(applictionDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
// 监听是否触发 home 键挂起App
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillResignActive), name: UIApplication.willResignActiveNotification, object: nil)
// 监听App是否被杀死
NotificationCenter.default.addObserver(self, selector: #selector(applicationKilled), name: UIApplication.willTerminateNotification, object: nil)
}
// 重新进入App时被调用
@objc func applictionDidBecomeActive() {
}
// 触发 home 键,App 挂起时被调用
@objc func applicationWillResignActive() {
}
// App是否被杀死时调用
@objc func applicationKilled() {
}
}
网友评论