Search code examples
iphoneiosvibration

how can I check if the iOS device can vibrate


Currently only iPhone supports the vibrations how can I check if my device supports vibrations before calling the vibration function.


Solution

  • The iOS sdk has two functions that would vibrate the iPhone. But Vibration hardware is present only on iPhones. So how will you alert your user who uses the app on iPad or iPod touches? Clearly, checking the model is not the way to go. There are two seemingly similar functions that take a parameter kSystemSoundID_Vibrate

    AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    

    Both the functions vibrate the iPhone. But when you use the first function on devices that don’t support vibration, it plays a beep sound. The second function on the other hand does nothing on unsupported devices.