Can an app keep the iPhone's screen from dimming or turning off?

Discussion in 'iOS Programming' started by mrsir2009, Oct 8, 2011.

  1. mrsir2009 macrumors 604

    mrsir2009

    Joined:
    Sep 17, 2009
    Location:
    Melbourne, Australia
    #1
    Can an app keep the iPhone's screen from dimming or turning off? So when the app is running the screen won't dim at all or turn off/sleep. If so, how can I go about implementing this in my app in XCode?
     
  2. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #2
    Code:
       UIApplication  *app = [UIApplication sharedApplication];
          
       if (!app.isIdleTimerDisabled)
          app.idleTimerDisabled = YES;
    
    Most of the time you need this only in one part of your application so you can turn this on and off as you enter/leave that part. For example in -viewDidAppear: and -viewDidDisappear: or whenever you feel you should stop wasting the battery without a proper cause.
     
  3. mrsir2009 thread starter macrumors 604

    mrsir2009

    Joined:
    Sep 17, 2009
    Location:
    Melbourne, Australia
    #3
    Where would I place the code if I wanted to waste the iPhone's battery life for the whole time the app is running? (Don't worry, there is a purpose for it BTW)

    Thanks!
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    That code could be placed anywhere early in your application's life cycle. If you don't know about an iOS application's life cycle yet, now would be a good time to read The Application Life Cycle section of the iOS Application Programming Guide.
     

Share This Page