I am trying to get the accelerometer values on a phone and return them in a function. The following code never gets to the "Reached" NSLog. I am calling this in my viewDidLoad and it goes into the if statement. Any help is greatly appreciated.
- (NSArray *)getAccelerometerValues{
//Get the current x y and z
__block float x, y, z;
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = .5;
if(motionManager.accelerometerAvailable){
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[motionManager startAccelerometerUpdatesToQueue:queue
withHandler:^(CMAccelerometerData *accelerometerData, NSError * error) {
NSLog(@"Reached");
x = (accelerometerData.acceleration.x * 180) / M_PI;
y = (accelerometerData.acceleration.y * 180) / M_PI;
z = (accelerometerData.acceleration.z * 180) / M_PI;
NSLog(@"X: %f Y: %f Z: %f",x,y,z);
}];
}
NSArray *xyz = [[NSArray alloc] initWithObjects:
[NSNumber numberWithFloat:x],
[NSNumber numberWithFloat:y],
[NSNumber numberWithFloat:z],
nil];
return xyz;