Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mrsir2009

macrumors 604
Original poster
Sep 17, 2009
7,505
156
Melbourne, Australia
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?
 
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.
 
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!
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.