How do I prevent the iPhone screen from dimming or turning off while my application is running?

前端 未结 5 1087
醉梦人生
醉梦人生 2020-11-29 16:53

I\'m working on an app that requires no user input, but I don\'t want the iPhone to enter the power saving mode.

Is it possible to disable power saving from an app?<

5条回答
  •  不知归路
    2020-11-29 17:30

    I have put this line of code in my view controller yet we still get customers saying the screen will dim or turn off until someone touches the screen. I have seen other posts where not only do you programatically set

    UIApplication.sharedApplication().idleTimerDisabled = true 
    

    to true but you must reset it to false first

    UIApplication.sharedApplication().idleTimerDisabled = false
    UIApplication.sharedApplication().idleTimerDisabled = true
    

    Sadly this still did not work and customers are still getting dimmed screens. We have Apple Configurator profile preventing the device from going to sleep, and still some devices screen go dim and the customer needs to press the home button to wake the screen. I now put this code into a timer that fires every 2.5 hours to reset the idle timer, hopefully this will work.

提交回复
热议问题