ios4detectiphone-vibrate

Detecting Vibration on a Table with the iPhone


is it possible to detect vibration on the iPhone? I'm trying to figure out how to detect when the user smacks a desk or table when the phone is sitting on it. I remember reading somewhere you could detect a smack on a wooden table using the mic and AVFoundation. Any ideas?

Thanks


Solution

  • if you go down the microphone route, something like this might do the trick:

    //somewhere during setup call this line
    [anAVAudioRecorder setMeteringEnabled:YES];
    
    //then in a method used to poll the audioMeter
    [anAVAudioRecorder updateMeters];
    averagePower = [anAVAudioRecorder averagePowerForChannel:0];
    if (averagePower > threshold ) {
        [musicPlayerClass play];
    }