Arnlee Vizcayno Arnlee Vizcayno - 6 months ago 46
iOS Question

How to disable/enable the sleep mode programmatically in iOS?

I have an app that must stay awake until the end of a countdown but it will go into 'sleep mode' whenever it reaches the allocated time to sleep.

In my app, I have the option to postpone sleep, so users can disable/enable it.

How do I do it programmatically?


You can disable the idle timer as follows;

In Objective-C:

[UIApplication sharedApplication].idleTimerDisabled = YES;

In Swift:

UIApplication.sharedApplication().idleTimerDisabled = true

Set it back to NO or false to re-enable sleep mode.

More about UIApplication Class.