1

I am working on an app where the user sets something (not important what it is) and then puts the phone down. After a little while, the user will pick the phone up again. I want to detect when the user picked up the phone. I am not very experienced with using the accelerometer. I tried to use the accelerometer a little bit but I noticed that I would have a problem because I am looking for movement, which is change from one position to another. If anybody knows how to do this, it would be greatly appreciated.

Thanks,

Kyle Rosenbluth
  • 1,672
  • 4
  • 22
  • 38
  • So basically your looking to detect wether the accelerometer registers anything? – Mick MacCallum Apr 04 '12 at 22:14
  • Yes, but it is a little more complicated than that. The accelerometer has to detect a movement that is more than just a vibration (like if the phone is son a piano, when it is being played the piano vibrates). – Kyle Rosenbluth Apr 04 '12 at 22:18

1 Answers1

3

You could try something like this, to fire you action when the accelerometers acceleration equals a value you specify.

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
     if(acceleration.y > 1.0f)
     {
         NSLog(@"acceleration > myValue");
     } 
}

This post may help you as well

Community
  • 1
  • 1
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • Thanks, this did the trick! I can't believe I didn't see how simple it is. – Kyle Rosenbluth Apr 04 '12 at 22:51
  • 2
    NOTE: This is deprecated in iOS 5.0. – Besi Mar 06 '13 at 09:50
  • Can we do this in some less resource consumption way? The accelerometer will demand a lot of battery, given the continuous updates. Are there any specific callbacks for a significant change? Like when you pick up iPhone6s it brightens the screen, what is apple doing behind the scenes? – nr5 May 01 '18 at 15:15