我的关注 |
¥0.1 swift3.0 如何监听用户按下Home键?
0

在swift3.0中如何监听用户按下Home键?以及APP在后台被KILL?和重新进入程序?

1个回答
0
采纳
  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3. //监听是否触发home键挂起程序.
  4. NotificationCenter.default.addObserver(self, selector: #selector(self.applicationWillResignActive), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
  5. ///监听是否重新进入程序程序.
  6. NotificationCenter.default.addObserver(self, selector: #selector(self.applicationDidBecomeActive), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
  7. ///监听是否被kill
  8. NotificationCenter.default.addObserver(self, selector: #selector(self.applicationWillTerminate), name: NSNotification.Name.UIApplicationWillTerminate, object: nil)
  9. }
  10. func applicationWillResignActive(){
  11. print("监听是否触发home键挂起程序.")
  12. }
  13. func applicationDidBecomeActive(){
  14. print("监听是否重新进入程序程序.")
  15. }
  16. func applicationWillTerminate(){
  17. print("监听是否进入后台或被kill")
  18. }
采纳答案
佛法不二
修改
评论 (0)
撰写回答