Is it possible to play already existing system sounds without importing your own?
I find this list of systemSoundID very useful for accessing the sound ID directly.
http://iphonedevwiki.net/index.php/AudioServices
For example, to play a key press tock sound.
#define systemSoundID 1104
AudioServicesPlaySystemSound (systemSoundID);
You'll also need to add the AudioToolbox framework in your project, and add #include <AudioToolbox.h>
to your .m or .h file.
This code plays apple system sound "Tock.aiff"..I believe you can play different system sounds using this
NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesDisposeSystemSoundID(soundID);
See this thread
https://developer.apple.com/documentation/audiotoolbox/system_sound_services
You can use this for all default system audio.
Example, for the tap sound user this:
AudioServicesPlaySystemSound(1104);
For positive sounds, use this:
AudioServicesPlaySystemSound(1054);
And, negative sounds use this:
AudioServicesPlaySystemSound(1053);
The complete list you can see here.
List of all system sounds: iOSSystemSoundsLibrary
After you import AVKit
, you can play all this sounds with:
AudioServicesPlaySystemSound (systemSoundID);
adapted from @yannc2021
http://iphonedevwiki.net/index.php/AudioServices
if you want to use system sound in Swift
// import this
import AVFoundation
// add this method
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
// declared system sound here
let systemSoundID: SystemSoundID = 1104
// to play sound
AudioServicesPlaySystemSound (systemSoundID)
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