iOS 5 conversion UIAccelerometer

core-motion, ios-simulator, ios5, uiaccelerometer

Solution

Start accelerometer.

- (void)startAccelerometerData {
    motionManager = [[CMMotionManager alloc] init];
    motionManager.accelerometerUpdateInterval = 1/60.0;

    [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
                                        withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
        NSLog(@"x:= %f y:= %f z:= %f", accelerometerData.acceleration.x, accelerometerData.acceleration.y, accelerometerData.acceleration.z);
    } ];
}

stop accelerometer

- (void)viewDidUnload  {
    [motionManager stopAccelerometerUpdates];
    motionManager = nil;
    [super viewDidUnload];
}

Problem

I'm using xcode 4.2 (and going to be upgrading soon) and these lines of code ``` [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)]; [[UIAccelerometer sharedAccelerometer] setDelegate:self]; ``` the code works but I have a yellow warning saying that the code is `deprecated` and I looked at the new references and `CoreMotion` now does the Accelerometer. I was wondering what is the new way to write something like the above..?

Original source