I want to measure the acceleration of the iPhone in the direction of the z-axis. However, the code I use measures the inclination, so the angle in which the device is located. But I want to measure the acceleration when the iPhone for example is lifted. Like some seismograph apps.
My code:
-(void)viewDidLoad
{
[super viewDidLoad];
myMotionManager = [[CMMotionManager alloc] init];
myMotionManager.accelerometerUpdateInterval = 0.1;
if ([myMotionManager isAccelerometerAvailable])
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[myMotionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
Label.text = [NSString stringWithFormat:@"%.2f",accelerometerData.acceleration.z];
});
}];
} else
NSLog(@"not active");
[super viewDidLoad];
}
Okay, i found the answer. I have to use userAcceleration