iOS: Can I detect if the device screen is on/off?
问题 How can I check if the screen is on or off in iOS? I'd like to know if the screen is currently on, even my app is in the background. I'd like to have an event listener on this. thanks. 回答1: In Swift 3 you can do: override func viewDidLoad() { super.viewDidLoad() // Observer UIApplicationDidBecomeActive,UIApplicationDidEnterBackground NotificationCenter.default.addObserver( self, selector: #selector(MyViewController.applicationDidBecomeActive(notification:)), name: NSNotification.Name