How to add sound for UILocalNotification?

user2813740 picture user2813740 · Jan 3, 2014 · Viewed 16.4k times · Source

I have done with basic notification for my App. I want to add sound effect to my notification.

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
    return;

localNotification.fireDate = [NSDate date];
//localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = msg;
localNotification.soundName = @"Morse.aiff";

[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];

How to add sound effect?

Answer

tilo picture tilo · Jan 3, 2014

You may want to start with reading Preparing Custom Alert Sounds of the Local and Push Notification Programming Guide (make sure that your custom sound is shorter than 30s).

If you want to use the default sound: use UILocalNotificationDefaultSoundName (as suggested by Euroboy)

Update: You seem to be not the only person experiencing this problem. A possible (but of course not a good) solution is described here.