Gyroscope




#import <CoreMotion/CoreMotion.h>


    self.motionManager = [[CMMotionManager alloc] init];



    //Gyroscope

    if([self.motionManager isGyroAvailable])

    {

        /* Start the gyroscope if it is not active already */ 

        if([self.motionManager isGyroActive] == NO)

        {

            /* Update us 2 times a second */

            [self.motionManager setGyroUpdateInterval:1.0f / 2.0f];


            /* And on a handler block object */


            /* Receive the gyroscope data on this block */

            [self.motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue]

             withHandler:^(CMGyroData *gyroData, NSError *error)

            {

                NSString *x = [[NSString alloc] initWithFormat:@"%.02f",gyroData.rotationRate.x];

                self.gyro_xaxis.text = x;


                NSString *y = [[NSString alloc] initWithFormat:@"%.02f",gyroData.rotationRate.y];

                self.gyro_yaxis.text = y;


                NSString *z = [[NSString alloc] initWithFormat:@"%.02f",gyroData.rotationRate.z];

                self.gyro_zaxis.text = z;

            }];

        }

    }

    else

    {

        NSLog(@"Gyroscope not Available!");

    }

}


http://stackoverflow.com/questions/7135934/ios-gyroscope-api





Posted by tenn
,