iPhone accelerometer:didAccelerate: seems to not get called while I am running a loop

Posted by AJ on Stack Overflow See other posts from Stack Overflow or by AJ
Published on 2010-04-22T04:21:35Z Indexed on 2010/04/22 4:23 UTC
Read the original article Hit count: 406

An accelerometer related question. (Sorry the formatting may not look right, its the first time I am using this site). I got the accelerometer working as expected using the standard code

UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 0.1;   //I also tried other update values

I use NSLog to log every time the accelerometer:didAccelerate: method in my class is called. The function gets called as expected and everything works fine till here.

However, when I run a loop, the above method doesn't seem to get called. Something like this

float firstAccelValue = globalAccel; //this is the x-accel value (stored in a global by the above method)
float nextAccelValue = firstAccelValue;

while (nextAccelValue == firstAccelValue){

    //do something
    nextAccelValue = globalAccel; // note globalAccel is updated by the accelerometer method

}

The above loop never exits, expectedly since the accelerometer:didAccelerate: method is not getting called, and hence globalAccel never changes value.

If I use a fixed condition to break the while loop, I can see that after the loop ends, the method calls work fine again.

Am I missing something obvious here? Or does the accelerometer method not fire when certain processing is being done?

Any help would be greatly appreciated! Thanks!

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.1.2

Related posts about uiaccelerometer