Plays a system sound as an alert.
- iOS 2.0+
- macOS 10.5+
- UIKit for Mac 13.0+Beta
- tvOS 9.0+
The system sound object to play as an alert.
Before using this function, call the
Audiofunction to obtain a system sound.
Services Create System Sound ID(_: _:)
Depending on the particular iOS device, this function plays a short sound and may invoke vibration. Calling this function does the following on various iOS devices:
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
recordaudio session category. This ensures that vibration doesn’t interfere with audio recording. For an explanation of audio session categories, see Categories Express Audio Roles.
iPod touch, original—plays a short alert melody.
iPod touch, 2nd generation and newer—plays the specified sound.
In iOS, the duration of the sound to be played must not be more than 30 seconds.
In macOS, when a user has configured System Preferences to flash the screen for alerts, or if sound cannot be rendered, calling this function will result in the screen flashing. In macOS, pass the constant
k to play the alert sound selected by the user in System Preferences. In iOS there is no preferred user alert sound.
To play a short sound not used as an alert, use