In the documentation of AudioServicesPlayAlertSound, it says I can disable vibration when playing a sound:
iPhone—plays the specified sound. If the user has configured the Settings application for vibration on ring, also invokes vibration. However, the device does not vibrate if your app’s audio session is configured with the AVAudioSessionCategoryPlayAndRecord or AVAudioSessionCategoryRecord audio session category.
However, I still feel vibration on my iPhone 4S (iOS 5.1.1) even after setting my category to "play and record". It rings and vibrates at the same time.
#import <AudioToolbox/AudioServices.h>
#import <AVFoundation/AVAudioSession.h>
NSError* error;
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayAndRecord
error:&error];
if (error == nil) {
AudioServicesPlayAlertSound(1000);
}
I've also tried AudioServicesPlaySystemSound
, but the results are the same. The reason why I want to disable vibration is because I am making an app where the user must place her phone far away and the phone should not topple over due to vibration.
Set vibration options for specific alerts: Go to Settings > Sounds & Haptics. See Change iPhone sounds and vibrations. Turn off all vibrations: Go to Settings > Accessibility > Touch, then turn off Vibration. Note: This setting turns off vibrations for earthquake, tsunami, and other emergency alerts.
System Sound Services provides a C interface for playing short sounds and for invoking vibration on iOS devices that support vibration. You can use System Sound Services to play short (30 seconds or shorter) sounds.
System Sounds is the audio produced directly by your operating system – such as Windows and OS X startup and shutdown sounds, error notifications, and other standard notifications.
I tested this with my iPhone 4s and it does exactly what you want.
NSError* error;
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayAndRecord
error:&error];
if (error == nil) {
SystemSoundID myAlertSound;
NSURL *url = [NSURL URLWithString:@"/System/Library/Audio/UISounds/new-mail.caf"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &myAlertSound);
AudioServicesPlaySystemSound(myAlertSound);
}
Use AudioServicesCreateSystemSoundID
to create a SystemSoundID
using the filename of the system sound. Then use AudioServicesPlaySystemSound()
to play the sound with no vibration. Filenames of the other system sounds can be found at the link below.
http://iphonedevwiki.net/index.php/AudioServices
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