Titanium Community Questions & Answer Archive

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

no sleep mode??

I can't get my iPhone app to work in sleep mode.
I've used Ti.App.idleTimerDisabled = true;
in app.js but the application just stops when the screen is dimmed and enters sleep mode.

am I missing something?
thanks!

— asked August 13th 2010 by Pedro Sousa
  • iphone
  • sleep
  • titanium
0 Comments

3 Answers

  • I found out if I play a piece of sound and add a timer in the pause event listener, my app continues to function. (except in iphone 3G).
    will this be accepted by apple?

    example:

    function duh(){
        Titanium.API.info("working");
    }
    
    Titanium.App.addEventListener('pause',function(e){
        sound_test.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAYBACK; 
        sound_test.looping = true;
        sound_test.play();
        var useless_timer = setInterval(duh,1000);
        sound_test.stop();
    
        Titanium.API.info("pausing APP");
    });
    
    — answered August 14th 2010 by Pedro Sousa
    permalink
    1 Comment
    • Interesting find. I'm also interested in an answer to your question.

      — commented August 17th 2010 by Fred Spencer
  • I did a bit more research and it seems timers do continue to work based on what NSTimer can do. Haven't looked through source, but I'm assuming setInterval is one of the timing bridges to that class.

    http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

    — answered August 17th 2010 by Fred Spencer
    permalink
    0 Comments
  • Hello,

    I'm facing a similar situation with my timer. When the phone locks the timer stops responding and picks up again when I a "resumed" event is triggered. I tested your solution and seems to offer a workable scenario. My question is how you stop the "useless_timer" from the "resumed" event. I tried clearInterval(duh) but doesn't seem to work. BTW how do you deal with the timer when going into background?

    Thanks

    Vassilis

    — answered April 17th 2011 by Vassilis Papakonstantinou
    permalink
    1 Comment
    • Playing/reading around found that the solution is clearInterval(useless_timer).

      — commented April 17th 2011 by Vassilis Papakonstantinou
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.