Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 663
user757812 Avatar asked Jun 03 '11 18:06

user757812


People also ask

How do I make IOS vibrate?

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.

How do I test my iPhone for vibrate?

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.

Why is vibration not supported on my iPhone?

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.

Do iphones vibrate anymore?

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.


3 Answers

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.

like image 177
Saurabh Avatar answered Sep 20 '22 20:09

Saurabh


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
}
like image 34
Michael Avatar answered Sep 17 '22 20:09

Michael


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.

like image 22
Stavash Avatar answered Sep 20 '22 20:09

Stavash