🗓 Aug 28, 2021⏳ 1 minutes
How to prevent the iOS app from going to sleep
Photo by Simon Infanger on Unsplash
By default every app adopts to system settings related to Auto-Lock:
Settings app -> Display & Brightness -> Auto-Lock
However, if we want to make sure that screen is never automatically locked and going to sleep due to inactivity when your app is running or performing any specific tasks (ie. navigating user, calculating data, loading new game level) you can set explicit value of isIdleTimerDisabled inside UIApplication object, ie. like this:
UIApplication.shared.isIdleTimerDisabled = true
Good practice suggests making sure that the app is not draining user battery when it’s not essential, that is why I would strongly recommend limiting usage of this feature to the cases when it is really needed, like binding it with lifecycle of ViewController performing key tasks for the app.