iOS SDK :: vibration & plays a beep sound.

Mangesh picture Mangesh · Jul 8, 2014 · Viewed 11k times · Source

I need to vibrate iOS device, devices that don’t support vibration, Will plays a beep sound.

For this I am using

Import AudioToolbox.framework
#import <AudioToolbox/AudioToolbox.h>

AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);

It vibrate on iPhone device, but No sound on iPad and iPod. While refrences say that it will play sound. What I am doing wrong ?

Making the iPhone vibrate

http://blog.mugunthkumar.com/coding/iphone-tutorial-better-way-to-check-capabilities-of-ios-devices/

Answer

lukaswelte picture lukaswelte · Jul 10, 2014

Try setting the AudioSession:

#import <AudioToolbox/AudioToolbox.h>

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;         
[audioSession setCategory: AVAudioSessionCategoryPlayback  error:&err];
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);         
//or: AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);