views:

973

answers:

5

I have an application that uses the accelerometer. Sometimes, the application will launch without the accelerometer data updating. Relaunching the app, sometimes the problem persist, sometimes it doesn't. And even weirder, sometimes I can try 10 times and everything works as expected. Is this a bug, or maybe something I am missing. Debugging, this code is never called when the accelerometer is not updated:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;

Any ideas?

A: 

I have this same problem. It happens perhaps 1/20 times with an app I made from the CrashLanding sample. After I noticed it with my app I grabbed a fresh version of Crashlanding, installed it, and finally got it to start with accelerometer failing.

I don't know how to fix it. Honestly I hate the accelerometer... at least for controlling games :-\

Also, the accelerometer has occasionally failed when I start the "accelerometer" sample project.

MrDatabase
+6  A: 

I finally found a work around. This is a known bug. So the work around I found is to start a thread and have this thread check if the accelerometer delegate has been called, if it has, then quit the thread, if not, set the delegate again, and re-test, until the accelerometer delegate gets called. I tested this throughly and it works flawlessly. I hope this gets resolved on the next update of the iPhone OS.

Carlos Hernandez
A: 

As others have mentioned, this is a known bug; I have logged the bug with Apple (Bug Reporter problem ID 6093028), perhaps others have done so as well. As far as I know, all apps that makes use of UIAccelerometer (including Apple's sample apps) suffer from this issue, though the frequency of occurance varies.

SytS
A: 

This could have been fixed with the fresh new 2.2. Can anyone confirm?

Steph Thirion
A: 

FWIW, my app is widely used and it uses the accelerometer, and I've never had this problem.

My use case may be different than yours: I only enable it on user request, well after the application is launched.

Marco