EDIT: added a global and now it's working. But I still have my doubts.. Please read on :)
I want to get the acceleration exercised on the Y-axis whenever I need to and use it in different parts of my code. In this example I'm using it inside a while-loop for testing purposes..
My code is working but Am I using the the UpdateToQueue... method correctly or is this kind of an "unorthodox" way of achieving what I want?
I've set the Update Interval at 30 ms, do you think this is a "safe" update interval ? I was told that I should be careful when choosing one because current or later hardware/iOS updates might not be able to keep up with such an interval is this true?
double myAcceleration; // a global..
-(void) play // my "main" method..
{
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
motionManager.deviceMotionUpdateInterval = 0.03; // update every 30ms
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
withHandler:^(CMDeviceMotion *motion, NSError *error)
{
myAcceleration = motion.userAcceleration.y;
}
];
while(!self.stopButtonPressed)
{
NSLog(@"Y-Axis acceleration is %f", myAcceleration);
}
}