监听前台后台事件
监听APP进入前台
进入该界面不会执行
所以应该在合适的位置设置代理
NotificationCenter.default.addObserver(self, selector: #selector(onEnterForeground), name: UIApplication.didBecomeActiveNotification, object: nil)
监听APP进入后台
NotificationCenter.default.addObserver(self, selector: #selector(onEnterBackground), name: UIApplication.willResignActiveNotification, object: nil)
进入了前台
@objc func onEnterForeground() {
print("SimpletPlayerController enterForeground")
}
进入了后台
@objc func onEnterBackground() {
print("SimpletPlayerController enterBackground")
}