views:

136

answers:

2

When my iPhone app resigns active status, the sharedAccelerometer singleton instance of UIAccelerometer stops sending accelerometer:didAccelerate: messages to my delegate.

Is it at all possible to continue receiving those messages, similarly to how the CLLocationManagerDelegate continues to receive updates when the app is inactive?

I would prefer not to have to disable the idleTimer altogether if it can be helped.

A: 

No, not in the most recent available form of the iPhone SDK at least.

refulgentis
A: 

I would say that it is possible since this app is on the AppStore:

However, since you move differently in bed during the different phases, the Sleep Cycle alarm clock is able to use the accelerometer in your iPhone to monitor your movement and determine which sleep phase you are in.

I can't believe it has to run all night with the screen turned on. EDIT: looks like it has to! :P


So they haven't got around that issue either. More chances that you can't achieve it then...

Have you read the documentation of the UIAccelerometer, does it mention anything there? If it just stops sending acceleration events there is not much you can do.

I would however try to set the accelerometer delegate again to my class when my app has lost focus (when the phone got locked). You can get that notification (lost focus notification) from the UIApplication. Try that just in case the accelerometer's delegate gets set to nil when the app loses focus.

Dimitris
Thanks for pointing me in the direction of this app. I downloaded it and can confirm that: 1) The app must be left active all night, 2) You cannot lock the phone, 3) You are instructed to place the phone face down on the bed, 4) You are instructed to keep the phone connected to the charger. Essentially, it looks like the app disables the idleTimer and keeps the screen active all night. Not a huge problem as long as the screen is face down and the phone is charging, but not an option for my app where the existence of a charger is very unlikely.
JonF
Then, I'm afraid you can't do what you want but you can try one last thing. Look at my updated answer and good luck :)
Dimitris