I'm trying to change the UILabel value if we tilt the device, for that i'm trying to implement CMMotionManager but its not working for me, this the code I'm using,
I have add CoreMotion in lib.
#import <CoreMotion/CoreMotion.h>
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = .2;
[motionManager startAccelerometerUpdates];
if ([motionManager isAccelerometerAvailable] == YES)
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:1];
[motionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData *data, NSError *error)
{
CMAcceleration acceleration = data.acceleration;
if(acceleration.y < -0.25) { // tilting the device to the right
[self setTextforlabel:@"right"];
} else if (acceleration.y > 0.25) { // tilting the device to the left
[self setTextforlabel:@"left"];
}
}];
}
whats the problem here, isAccelerometerAvailable
is always false and
startAccelerometerUpdatesToQueue
it will not fire in.
can any one help me for this or there any other way to do for tilt device.