Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Wake Lock - stop the phone powering off

What is the simplest way to stop the phone (iPhone) going into an automated sleep mode? I don't mind the screen going off but I want the app to continue running. In android java it is known as a wakelock.

— asked March 18th 2010 by Paul Burrowes
  • mobile
  • sleep
0 Comments

3 Answers

  • Accepted Answer

    Place the below in your app.js should do the trick.

    Ti.App.idleTimerDisabled = true; // to disable going to sleep

    If you want to enable it you just do the following

    Ti.App.idleTimerDisabled = false; // to re-enable it

    Works on the iPhone, not sure about Android

    — answered March 18th 2010 by Ben Bahrenburg
    permalink
    0 Comments
  • Hmmm??!!

    In my App, this works only for some minutes after the iPhone Display is dimming.

    Ti.App.idleTimerDisabled = true;
    
    setInterval(function(){BeepBeep();},120000);
    
    function BeepBeep(){
    
    var date = new Date();
    var notification = Ti.App.iOS.scheduleLocalNotification({
        sound:"TheTone.caf",
        date:new Date(new Date().getTime() + 0) // 0 seconds after backgrounding
    });
    };
    

    But then, the iPhone sleeps anyway !

    PS: The code here is a part from "bg.js" (Background Service) i first had initialized in app.js with :

    var service = Ti.App.iOS.registerBackgroundService({
            url:'bg.js'
            });
    

    What can i do to stop the sleep mode !!

    — answered August 17th 2011 by Hansjuerg Wuethrich
    permalink
    0 Comments
  • Perfect, thanks very much Ben!

    — answered March 19th 2010 by Paul Burrowes
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.