2

I am trying to set custom local notification sound like this:

UILocalNotification *notification = [UILocalNotification new];
notification.timeZone = [NSTimeZone systemTimeZone];
notification.fireDate = date;

notification.alertAction = @"123"; 
notification.alertBody = @"123";

//!!!
notification.soundName = @"Glass.aiff";

alarmID=[NSString stringWithFormat:@"%i", arrayAlarms.count];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:alarmID forKey:@"id"]; 
notification.userInfo = infoDict; 
notification.repeatInterval=NSWeekCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

But I hear only default sound. I am testing app on ios5. Great thanks for help in advance and sorry for my english.

Ajumal
  • 1,048
  • 11
  • 33
user1270014
  • 21
  • 1
  • 4

4 Answers4

2

Custom Notification sounds are restricted to less than 30 seconds. If your sound is longer than this iOS will play the default sound instead. Could this be your problem?

For more info see here. https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html

"Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead."

Himanshu A Jadav
  • 2,286
  • 22
  • 34
Daniel Bowden
  • 988
  • 1
  • 10
  • 23
  • No, the problem seem to be that at the line 'notification.soundName = @"Glass.aiff";' the sound is not given *correctly*. It looks like the name of the sound is not enough. Because the Glass.aiff sound, IS less than 30 seconds. It looks like the only way to play Glass.aiff is to include it in your app. This is fairly stupid, because you have to include a file that is already included in your device by the iOS! (OK, its not a big file, but still... imagine if you want your user to be able to select from all available (iOS) sounds. You can't! You have to include all (14) of them!) – Gik Nov 01 '12 at 09:41
  • 1
    This page may help: http://iphonedevwiki.net/index.php/AudioServices perhaps it is not actually called Glass on the filesystem and is actually something like "sms-received2.caf"? Once you find the sound filename you want I believe this answer might help you: http://stackoverflow.com/a/7831768/387317 – Daniel Bowden Nov 01 '12 at 22:24
  • That (the second link) works, BUT only for 3 (yes 3) sounds. The .caf sounds (of the 1st link) are nowhere to be found. So we are back to square 1 (almost). – Gik Nov 03 '12 at 14:30
-1

Check your syntax , its wrong. check with this,

notification.soundName = "Glass.aiff";

Ramdhas
  • 1,765
  • 1
  • 18
  • 26
-1

One can still use UILocalNotificationDefaultSoundName for default local notification sound.

Eli
  • 1
-1

notification.soundName = @"Glass.aiff";

That should work. Make sure the sound(Glass.aiff) is actually in your app’s bundle, and is under 30 seconds.We can't set a custom sound that not present in our app's bundle ie from Document folder etc.

Vicky
  • 1,095
  • 16
  • 15