We recently came across a problem that stumped us for quite a while. We needed to have a timer run some code every second the app was open. This is fine until you lock your iDevice.
We noticed that when we manually locked the device and come back that the timer had stopped. It turns out that you can apply a fairly simple solution to this problem.
By playing a sound continuously, you force the device to keep working even after it is locked. We added a tiny sound file to our project and set it on loop with the volume turned off. In Titanium the code looks like this:
And viola. All timers continue running even when you manually lock. Just be
sure to stop and release the sound when you don’t need it to conserve battery.