¥0.1
swift3.0 如何监听用户按下Home键?
1个回答
0
采纳
override func viewDidLoad() {
super.viewDidLoad()
//监听是否触发home键挂起程序.
NotificationCenter.default.addObserver(self, selector: #selector(self.applicationWillResignActive), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
///监听是否重新进入程序程序.
NotificationCenter.default.addObserver(self, selector: #selector(self.applicationDidBecomeActive), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
///监听是否被kill
NotificationCenter.default.addObserver(self, selector: #selector(self.applicationWillTerminate), name: NSNotification.Name.UIApplicationWillTerminate, object: nil)
}
func applicationWillResignActive(){
print("监听是否触发home键挂起程序.")
}
func applicationDidBecomeActive(){
print("监听是否重新进入程序程序.")
}
func applicationWillTerminate(){
print("监听是否进入后台或被kill")
}
撰写回答