Titanium Community Questions & Answer Archive

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

Event for iPhone Lock and Unlock?

Hello,

Having a great time with 1.0, but I haven't been able to find a window event for when the iPhone is locked or unlocked. I hoped blur and focus would fire, but they don't seem to be.

Is there another event I'm missing?

I ask because I have a timer running that does fine when the app is open. But with the app running, if the iPhone is locked, when I unlock it, the timer is way behind. My guess is the iPhone slows down its CPU while locked and it's messing up my timer.

I think I could deal with it there were lock / unlock events.

Thanks for any help!

Steve

— asked March 11th 2010 by Steve Perlow
  • event
  • iphone
  • lock
  • timer
  • unlock
0 Comments

4 Answers

  • Hi guys,

    It works but the 'pause' event is actually executed when we re-open the app (just before the 'resume' event)

    You can check that in kitechen sink, you can see that it goes from "App has resumed" to "App has been paused" to "App has resumed" only when we re-open the app

    I'm looking for a way to open a black view when 'pausing' the app, it does not actually work with this 'pause' event

    Any advices?

    Thanks guys!

    — answered April 13th 2011 by Robin D. (Perspecteev)
    permalink
    1 Comment
    • I'm having this same issue. I'm trying to hide personal information behind a passcode lock screen like the one built into iOS.

      The problem is that the passcode screen doesn't appear until a split second after resuming the application, which briefly exposes the user's personal information.

      Anyone know of any workarounds?

      — commented March 9th 2012 by Dylan Hand
  • I was facing the same issue and came up with the following work around. I created two variables one for the background state and one for the locked state and I assign them both as false through the pause event. In the subsequent resume event I change only the background variable to true and keep the locked variable to false and then in the resumed event (that fires after the resume event) I assigned the locked variable to true and then check if both are true which is the case of the app resuming from the background or if only the second (locked) is true which is the case of resuming from lock.

    — answered April 24th 2011 by Vassilis Papakonstantinou
    permalink
    0 Comments
  • Woohoo! Found it in Kitchen Sink. It's in the "app_events.js" example (and pasted below). It's the pause and resume event for an App.

    Also, please disregard my guess above about the CPU slowing down. Clearly, pause and resume is what's going on.

    Titanium.App.addEventListener('pause',function(e)
    {
        paused = true;
        label.text = "App has been paused";
    });
    
    Titanium.App.addEventListener('resume',function(e)
    {
        if (paused)
        {
            label.text = "App has resumed";
        }
        else
        {
            label.text = "App has resumed (w/o pause)";
        }
    });
    
    — answered March 11th 2010 by Steve Perlow
    permalink
    1 Comment
    • Note in the above code it ought to reset paused = false in the resume listener.

      — commented July 11th 2012 by ERIC HERRMANN
  • you can unlock your iPhone now easily with Unlock IMEI tool which is developed with the latest technologies and so unlocks your iPhone's IMEI just in few minutes without effecting any other application.

    — answered July 3rd 2013 by pearl stella
    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.