-(void) play
{
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdates];
BOOL timeReached = NO;
while(!self.stopButtonPressed)
{
if(motionManager.deviceMotion.userAcceleration.y >= ... && motionManager.deviceMotion.userAcceleration.y <= ...)
{
//start timer
}
while(motionManager.deviceMotion.userAcceleration.y >= ... && motionManager.deviceMotion.userAcceleration.y <= ... && !timeReached)
{
if(//check timer & if timer is >=300ms)
{
timeReached = YES;
NSLog(@"acceleration on Y-axis stayed between ... & .. for at least 300ms");
}
}
}
}
-(void) play { CMMotionManager *motionManager = [[CMMotionManager alloc] init]; [motionManager startDeviceMotionUpdates]; BOOL timeReached =
Share
It seems like you’re going about this the wrong way; instead of running a clock, you should be setting
accelerometerUpdateIntervalto whatever you’re looking for and usingstartAccelerometerUpdatesToQueue:withHandler:to receive the data.From the Apple documentation:
Once you’ve set everything up, let it run. When you’ve received a completion notice from the block look at the data you’ve received.