How do I prevent an iOS device from going to sleep mode?

When most apps have no touches as user input for a short period, the system puts the device into a "sleep” state where the screen dims. This is done for the purposes of conserving power.

Preventing iOS Device from going to sleep is easy, navigate to your Settings → Display & Brightness → Autolock, select never.

This will never lock your screen.

If you’re developing an iOS Application and you’re required to implement this feature, you should use isidletimerdisabled provided by apple, to read more about it

In your viewDidLoad method write the following line of code to prevent the device from going to sleep.

UIApplication.shared.isIdleTimerDisabled = true