美文网首页
[006]Swift 监听是否重新进入App、是否触发 home

[006]Swift 监听是否重新进入App、是否触发 home

作者: 快乐捣蛋鬼 | 来源:发表于2019-06-28 11:11 被阅读0次
    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() {
            
        }
        
    }
    

    相关文章

      网友评论

          本文标题:[006]Swift 监听是否重新进入App、是否触发 home

          本文链接:https://www.haomeiwen.com/subject/jekscctx.html