Get iPhone to Vibrate

2020-07-25 01:33发布

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条回答
做个烂人
2楼-- · 2020-07-25 01:44

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.

查看更多
何必那么认真
3楼-- · 2020-07-25 01:52

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

查看更多
我命由我不由天
4楼-- · 2020-07-25 01:54

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.

查看更多
神经病院院长
5楼-- · 2020-07-25 02:02

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.

查看更多
登录 后发表回答