---
title: "AudioServicesPlayAlertSound(_:)"
framework: audiotoolbox
role: symbol
role_heading: Function
path: "audiotoolbox/audioservicesplayalertsound(_:)"
---

# AudioServicesPlayAlertSound(_:)

Plays a system sound as an alert.

## Declaration

```swift
func AudioServicesPlayAlertSound(_ inSystemSoundID: SystemSoundID)
```

## Parameters

- `inSystemSoundID`: The system sound object to play as an alert. Before using this function, call the doc://com.apple.audiotoolbox/documentation/AudioToolbox/AudioServicesCreateSystemSoundID(_:_:) function to obtain a system sound.

## Discussion

Discussion 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  playAndRecord or record audio 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. note: System-supplied alert sounds and system-supplied user-interface sound effects are not available to your iOS application. For example, using the kSystemSoundID_UserPreferredAlert constant as a parameter to the AudioServicesPlayAlertSound function will not play anything. 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 kSystemSoundID_UserPreferredAlert 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 AudioServicesPlaySystemSound(_:).

## See Also

### Related Documentation

- [AudioServicesCreateSystemSoundID(_:_:)](audiotoolbox/audioservicescreatesystemsoundid(_:_:).md)

### Playing Sounds

- [AudioServicesPlayAlertSoundWithCompletion(_:_:)](audiotoolbox/audioservicesplayalertsoundwithcompletion(_:_:).md)
- [AudioServicesPlaySystemSoundWithCompletion(_:_:)](audiotoolbox/audioservicesplaysystemsoundwithcompletion(_:_:).md)
- [AudioServicesPlaySystemSound(_:)](audiotoolbox/audioservicesplaysystemsound(_:).md)
