I want to retrieve the iPh开发者_如何学Cone's accelerometer values and print them into a label.
Any help is appreciated.
Put this in viewDidLoad method of your ViewController which is UIAccelerometerDelegate:
UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.updateInterval = 1.0f/60.0f;
accelerometer.delegate = self;
Then add this method:
-(void)accelerometer:(UIAccelerometer *)acelerometer didAccelerate:(UIAcceleration*)acceleration
{
// here you can use acceleration.x, acceleration.y, acceleration.z
}
精彩评论