Mahdi Appleseed Mahdi Appleseed - 2 months ago 21
Swift Question

UILocalNotification Sound Not Working

i'm a swift programmer and i have some problems with sound of UILocalNotification
i have the user permissions in app delegate . it's my code :

var nottypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
var notsettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: nottypes, categories: nil)

it's code for notification :

var notification:UILocalNotification = UILocalNotification()
notification.alertBody = "Simple"
notification.alertTitle = "Back To App!"
notification.fireDate = NSDate(timeIntervalSinceNow: 20)
notification.soundName = "Chord"


You should always take a look at the documentation before posting a question at S.O. If you read the first line of the definition of soundName's property it says:

For this property, specify the filename (including extension) of a sound resource in the app’s main bundle or UILocalNotificationDefaultSoundName to request the default system sound. When the system displays an alert for a local notification or badges an app icon, it plays this sound. The default value is nil (no sound). Sounds that last longer than 30 seconds are not supported. If you specify a file with a sound that plays over 30 seconds, the default sound is played instead.

So try:

notification.soundName = "Chord.mp3"   // use .mp3 or your file extension if it is not an mp3