2

I've been trying to make the iPhone Vibrate using this code:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

But is not working, could it be because I am playing sound at the same time as calling this?

4
  • Just tried it without the sound, still doesn't work. Any ideas?
    – Joshua
    Commented Jul 30, 2010 at 17:24
  • Keep in mind that this function call only vibrates on the iPhone. If you run this on an iPod touch, nothing happens. (Not sure about an iPad.) developer.apple.com/iphone/library/documentation/AudioToolbox/…
    – BP.
    Commented Jul 30, 2010 at 18:12
  • @BP not true. On the iPod, it will trigger the saw wave sound (or is it square wave?) -- beep boop beep boop. Commented Jul 30, 2010 at 18:24
  • 1
    I have tried this and also cannot get my phone to vibrate. I have turned on both vibrate settings (Vibrate on Ring and Vibrate on Silent). I am running iOS 6.0.1. Does anyone else have this issue?
    – jowie
    Commented Dec 4, 2012 at 10:14

4 Answers 4

15

If this helps anyone, I discovered that the vibrate command won't work while AVAudioRecorder is recording. Getting round this is very simple. You just have to stop your recorder first and resume it afterwards:

[recorder stop];
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
[recorder record];

This even works if you want to record sound and vibrate in the background using UIBackgroundModes.

1
  • 1
    :) It's good when you find someone who had exactly the same problem as you!
    – jowie
    Commented Apr 17, 2013 at 14:14
5

That should work fine. Has vibration been turned off on the device?

5
  • Checked settings, it's on. Is there any way to test it to make sure it works??
    – Joshua
    Commented Jul 30, 2010 at 18:09
  • Are you sure the device can vibrate at all? If you turn the sound switch off and on, does it vibrate? Commented Jul 30, 2010 at 18:25
  • Which sound switch? The vibrate one?
    – Joshua
    Commented Jul 31, 2010 at 6:43
  • Sorry, I mean the mute toggle on the side. Commented Jul 31, 2010 at 17:06
  • Also, don't forget to #import <AudioToolbox/AudioToolbox.h> Commented Jan 9, 2014 at 20:12
3

I'm using that code successfully on iPhone 4. It's not clear from the documentation of System Sound, but that code works only if the vibration is enabled in Settings.

Of course note that there are two different settings for the vibration: silent mode and normal mode. Toggling the Ring/Silent switch to Silent is not sufficient to enable vibration.

I guess you've already tried enabling the vibration in your device Settings, but worth highlighting this anyway.

0

On all iPhones that I've tested on (original, 3GS, and 4), it should vibrate. On the iPod touch 1st generation, it'll play a beep through the built-in speaker. On the iPod touch 2nd generation, it won't do anything. On the iPad, it won't do anything either. Those are all the devices I've tested on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.