0

What i want to do is read the acceleration.y and do something like:

if (acceleration.y > 0.8) {
   // Do something
}

As didAccelerate is deprecated I wonder how to get the y-value:

motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.accelerometerUpdateInterval = kUpdateInterval;

if (motionManager.accelerometerAvailable) {
    [motionManager startAccelerometerUpdates];
}
else {
    //this device doesn't have accelerometer notice somewhere??
}

- (void)startAccelerometerUpdates {
 // READ Y-VALUE?????
}

I want to use raw accelerometer data so the app also works on 3GS. Is it possible to read the Y-value?

Michael
  • 997
  • 1
  • 7
  • 13

2 Answers2

2

EDIT: the answer below is deprecated, check these posts for the right way.


Old answer:

Use a UIAccelerometer singleton instance for this, for example in your AppDelegate

//in your launching method
    UIAccelerometer * accel = [UIAccelerometer sharedAccelerometer];
    accel.delegate = self;

//delegate method:
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
    // use the y-property of the acceleration
}
Community
  • 1
  • 1
0

Look at the CMMotionManager class reference and search section named "Handing Motion Updates at Specified Intervals". In the "Accelerometer" bullet, it says

Set the accelerometerUpdateInterval property to specify an update interval. Call the startAccelerometerUpdatesToQueue:withHandler: method, passing in a block of type CMAccelerometerHandler. Accelerometer data is passed into the block as CMAccelerometerData objects.

CMAccelerometerData has a reference to CMAcceleration which is a struct that holds per axis acceleration.

barley
  • 4,403
  • 25
  • 28