In iOS application development, audio playback is a common requirement. iOS provides many ways to implement audio playback, one of which is to use AudioServicesPlaySystemSound
functions. This article will introduce how to use AudioServicesPlaySystemSound
functions to play system sounds in iOS applications.
First, we need to import AudioToolbox
the framework in order to use the relevant audio service functions. In your Xcode project, open the project navigator, select your project, and then select the "Build Phases" tab. Click the "+" button in the "Link Binary With Libraries" section, search and add "AudioToolbox.framework".
Next, we can use AudioServicesPlaySystemSound
functions to play system sounds. This function accepts a SystemSoundID
parameter that specifies the sound file to be played. We can use AudioServicesCreateSystemSoundID
functions to create one SystemSoundID
. Here is a sample code:
import AudioToolbox
func playSystemSound()