iPhone detect that user moved up their device

Go To StackoverFlow.com

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,

2012-04-04 22:07
by Kyle Rosenbluth
So basically your looking to detect wether the accelerometer registers anything - Mick MacCallum 2012-04-04 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 2012-04-04 22:18


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

2012-04-04 22:25
by Mick MacCallum
Thanks, this did the trick! I can't believe I didn't see how simple it is - Kyle Rosenbluth 2012-04-04 22:51
NOTE: This is deprecated in iOS 5.0 - Besi 2013-03-06 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 2018-05-01 15:15
Ads