I'm trying to implement a function that detects a user shaking his/her iPhone, and then the app will make a barking sound. So far I've got the code attached below, and it works. But, if I shake the phone harder, it makes 2 or more barks one immediately after the other. How do I make sure this only happens once per shake, no matter how hard?
- (void)accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration {
if (acceleration.x > kAccelerationThreshold ||
acceleration.y > kAccelerationThreshold ||
acceleration.z > kAccelerationThreshold) {
// BARKING SOUND
}
}