Currently only iPhone supports the vibrations how can I check if my device supports vibrations before calling the vibration function.
Go to Settings > Sounds & Haptics or Settings > Sounds. Select an option (like Ringtone or New Mail) under Sounds and Haptic Patterns or Sounds and Vibration Patterns. Tap Vibration, then tap Create New Vibration.
Test the Vibration Motor on the iPhoneFlip your iPhone's Ring/Silent switch back and forth. You will find it located right above the volume buttons on the left-hand side of your phone. If “Vibrate on Ring” or “Vibrate on Silent” is turned on in Settings, then you should feel a buzz.
Turn On Vibration In Accessibility Settings If Vibration is turned off in Accessibility settings, your iPhone won't vibrate even if the vibration motor is fully functional. Go to Settings -> Accessibility -> Touch and make sure the switch next to Vibration is turned on.
Unfortunately, there's no way to enable vibration for calls and texts only on your iPhone right now. Once you toggle off System Haptics or Vibration, it turns off all iPhone vibrations. However, you can sacrifice vibration on Ring mode to make your iPhone vibrate only in Silent mode.
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.
A bit of a work-around but I've found this to work. It's based on the assumption that only iPhone devices currently have the vibrate hardware in them.
if([[UIDevice currentDevice].model isEqualToString:@"iPhone"])
{
// An iPhone: so should have vibrate
}
else
{
// Not an iPhone: so doesn't have vibrate
}
Unfortunately there is no documented method for testing whether or not the device supports vibration. From documentation:
On some iOS devices, you can pass the kSystemSoundID_Vibrate constant to invoke vibration. On other iOS devices, calling this function with that constant does nothing.
Looks like the correct approach here would be to simply call the methods mentioned by Saurabh without checking if vibration is supported.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With