Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom iOS UILocalNotification sound does not play (possibly related to Xcode update)

I'm trying to get a custom sound working on a UILocalNotification, and I'm just getting no sound at all. If I use UILocalNotificationDefaultSoundName, I indeed get the default sound, but when the custom sound is specified, there is no sound, just the message. The sound is less than 30 seconds and it's in the right format, as far as I can tell. Here's a screenshot of the file info:

I've inspected the .app directory in XCode's DerivedData directory, and the alarm.caf file is at the root of the app, which I believe means it's in the bundle (right?).

I'm pretty sure this was working a while ago, and I've since upgraded Xcode. Maybe that is a hint?

I've also tried deleting/reinstalling/rebooting as mentioned in other answers. As you can see, I'm calling cancelAllLocalNotifications first.

Does anyone have any idea what could be wrong?

[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSLog(@"installing alarm");
[arguments pop]; // name
[arguments pop]; // title
alarm.alertBody = [arguments pop];
alarm.fireDate = [[NSDate date] addTimeInterval:[[arguments pop] intValue]/1000];
//alarm.soundName = UILocalNotificationDefaultSoundName;
alarm.soundName = @"alarm.caf";

[[UIApplication sharedApplication] scheduleLocalNotification:alarm];
like image 734
Al Wold Avatar asked Jun 27 '12 22:06

Al Wold


2 Answers

Your code seems to be good.

Try to clean your project, uninstall your app from your device/simulator, then re-install it. It could help maybe :)

like image 118
Vinestro Avatar answered Nov 08 '22 04:11

Vinestro


I don't know the reason (and I didn't read documentation too), I just turned on the action property notification setHasAction:YES and the sound began to play.

like image 2
Lovato Avatar answered Nov 08 '22 04:11

Lovato