0

I want to get direction of the device motion by using accelerometer. I tried method suggested here as below :-

- (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler {

    if (fabsf(aceler.x) > 1.5)
    {
        shake = YES;
        NSTimeInterval myInterval = .75;
        [NSTimer scheduledTimerWithTimeInterval:myInterval target:self selector:@selector(endShake) userInfo:nil repeats:NO];
        return;
    }

    if(shake)
    {
        totalG += aceler.x;
    }
}

- (void) endShake {
    shake = NO;
    int direction;
    if (totalG isLessThan 0) direction = 1;
    if(totalG isGreaterThan 0) direction = -1;
    [self changePageByShake:direction];
    totalG = 0;
}

But it's not giving accurate results. Is there any standard way to get the direction of the device ?

Note :- This is different from orientation of the device.

Community
  • 1
  • 1
ios developer
  • 3,363
  • 3
  • 51
  • 111
  • 1
    Can you check this one? it may help https://www.safaribooksonline.com/library/view/basic-sensors-in/9781449309480/ch04.html – aBilal17 May 04 '15 at 11:19
  • possible duplicate of [iPhone Accelerometer direction](http://stackoverflow.com/questions/13439915/iphone-accelerometer-direction) – kiranpradeep May 04 '15 at 17:29

0 Answers0