Class

UNNotificationSound

A sound to be played when a notification is delivered.

Overview

AUNNotificationSound 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 UNNotificationContent 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:

  • Linear PCM

  • MA4 (IMA/ADPCM)

  • µLaw

  • aLaw

You can package the audio data in an aiff, wav, or 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.

Topics

Getting Notification Sounds

class func `default`()

Returns an object representing the default sound for notifications.

init(named: String)

Creates and returns a notification sound object that plays the specified sound file.

Relationships

Inherits From

See Also

Notification Content

class UNMutableNotificationContent

The editable content for a notification.

class UNNotificationContent

The uneditable content of a local or remote notification.

class UNNotificationAttachment

A media file associated with a notification.