Kyle Rosenbluth Kyle Rosenbluth - 1 year ago 59
iOS Question

iPhone detect that user moved up their device

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.


Answer Source

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