A sound to be played when a notification is delivered.
- iOS 10.0+
- watchOS 3.0+
UNNotification object encompasses the information needed to play a sound with a notification. A sound object can represent the default alert sound or a custom sound that you provide.
Use the methods of this class to create a sound object, and then assign that sound to the
sound property of your
UNNotification object. To use the user’s preferred alert sound, use the
default() method to create the sound object. To specify a custom sound, use the
init(named:) method. Files for custom sounds must be located in your executable’s main bundle or in the
Library/Sounds directory of your app’s container directory.
Custom alert sounds are played by the system sound facility, so they must be in one of the following audio data formats:
You can package the audio data in an
caf file. Sound files must be less than 30 seconds in length. If the sound file is longer than 30 seconds, the system plays the default sound instead. For more information about preparing custom alert sounds, see Local and Remote Notification Programming Guide.