13

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?

tilo
  • 14,009
  • 6
  • 68
  • 85
user2813740
  • 517
  • 1
  • 7
  • 29
  • 1
    "localNotification.soundName = @"Morse.aiff";" is the property for sound just you should have a sound file with same name in your bundle resource. – spider1983 Jan 03 '14 at 07:08
  • can i use default sound mention in Library/Sounds .. if yes how to use? as i do not have any specific sound for Alert view… can i get to download some where... – user2813740 Jan 03 '14 at 07:14
  • 3
    Also look in Notification Center Settings,choose your app and make sure that sound in enabled. To use default sound you need this: `localNotification.soundName = UILocalNotificationDefaultSoundName;` – iOS Dev Jan 03 '14 at 07:20
  • yes i already tried that one but no sound is coming… i mean nothing.. is that i need to add any framework or some thing or any setting i have to do... – user2813740 Jan 03 '14 at 09:04
  • If you use iOS7, notification sounds are disabled by default. Only user can turn it on. – Shmidt Jan 03 '14 at 12:59
  • i am working on my App … i am testing with my APP and my IPad, setting everything is ON... – user2813740 Jan 04 '14 at 09:18

5 Answers5

13

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.

Community
  • 1
  • 1
tilo
  • 14,009
  • 6
  • 68
  • 85
  • yes i already tried that one but no sound is coming. is that i need to add any framework or some thing or any setting i have to do... – user2813740 Jan 03 '14 at 11:00
  • Are you using a custom sound, or the default one? – tilo Jan 03 '14 at 12:03
  • i tried default one .. but i could not hear any thing so i thought if possible to use custom, i can use default one no problem as long as i am getting some sound effect on Notification message. but it was not working... – user2813740 Jan 03 '14 at 12:19
  • I'm also using the default as suggested and I'm hearing nothing? – anders Feb 27 '14 at 17:36
2

In my case the problem was that I forgot to register for UIUserNotificationTypeSound. Without registration to UIUserNotificationTypeSound your App will not have the 'Sounds' option available under the Notifications Settings.

Here is the code snippet from the Local and Remote Notification Programming Guide (tilo already added a link to it above).

UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

After adding that code you can enable the sound option in Notification Settings for your App.

maitee
  • 51
  • 2
1

I had similar problem while trying to play mp3 file as local notification sound. Sound was shorter than 30 seconds, it was bundled, everything appears regular on the surface. After few hours i have realised that problem was caused by online mp3 cutter tool. I have find better editor, and file became playable on notification.

If mp3 file is edited with some tool, it is possible that something was missed by edit tool.

May be your problem is also caused by sound editor, or sound format converter.

slobodans
  • 859
  • 1
  • 17
  • 23
0

I found really simple solution for playing custom sound in local notification. 1. Normally sound will be work perfectly with aiff format. 2. When you added custom sound, please check if this sound added to the "Build Phases" 3. You already added your custom sound but basic system alert playing again? - delete application from your device and reboot. After connect your device and compile application again. 4. Profit! it will be work!

PS: This is solution if you have iOS 10. How i am understanding this is system bag..

Genevios
  • 1,115
  • 1
  • 16
  • 29
0

You need to make sure the resource file has your Target membership selected. For my case, it was not checked, and notification was still the system default one.

X.Y.
  • 13,726
  • 10
  • 50
  • 63