I have my own sound that I want to play while the phone vibrates, the most common thing to do is to do:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
but this is using the system's sound. Is there a way to use my own sound? What is the format of the sound that I can use?
Ringtones play for incoming calls, clock alarms, and the clock timer; text tones are used for text messages, new voicemail, and other alerts. Tap Vibration, then choose a vibration pattern, or tap Create New Vibration to create your own.
Launch the Settings app on your iPhone. Tap Sounds & Haptics. Tap on the alert category you'd like to set a custom vibration for. In this example, I'll use Text Tone.
Choose when your device vibrates On iPhone 7 and later, go to Settings > Sounds & Haptics. On earlier iPhone models, go to Settings > Sounds. You can choose if you want your iPhone to vibrate when set to Ring or Silent mode. If you turn off both settings, your iPhone won't vibrate.
Check out AudioServicesPlayAlertSound, this will play a custom sound and vibrate if the user has vibration enabled in their sound settings. The proper usage would be something like this...
SystemSoundID soundFileObject;
NSURL * soundFileURL= [[NSBundle mainBundle] URLForResource: @"mySoundFile" withExtension: @"aif"];
CFURLRef soundFileURLRef = (CFURLRef) [soundFileURL retain];
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);
AudioServicesPlayAlertSound (soundFileObject);
The supported file types are .caf, .aif, or .wav according to the above link. Hope that helps!
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