#import <CoreMotion/CoreMotion.h>
@property (strong) CMMotionManager *motionManager;
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_motionManager = [[CMMotionManager alloc]init];
_motionManager.gyroUpdateInterval = 0.1;
if(_motionManager.gyroAvailable) {
[_motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMGyroData *gyroData, NSError *error) {
printf("%lf, %lf, %lf\n", gyroData.rotationRate.x, gyroData.rotationRate.y, gyroData.rotationRate.z);
_glView.rotx -= gyroData.rotationRate.x/8;
_glView.roty -= gyroData.rotationRate.y/8;
}];
}
}
- (void) viewWillDisappear:(BOOL)animated
{
if(_motionManager.gyroActive)
[_motionManager stopGyroUpdates];
[super viewWillDisappear:animated];
}
Build Phases --> Link Binary With Libraries --> [+] --> CoreMotion.framework