IOS UILocalNotification custom sound not playing (possibly due to Xcode update)

I am trying to get a custom sound that works on UILocalNotification , and I just don't get any sound. If I use UILocalNotificationDefaultSoundName , I really get the default sound, but when a custom sound is set, there is no sound, just a message. As far as I can tell, the sound is less than 30 seconds and it is in the correct format. Here is a screenshot of the file information:

I checked the .app directory in the Xcode DerivedData directory, and the alarm.caf file is in the root directory of the application, which I believe means it in the package (right?).

I am sure this worked a while ago, and since then I have updated Xcode. Maybe this is a hint?

I also tried uninstalling / reinstalling / rebooting as mentioned in other answers. As you can see, I first call cancelAllLocalNotifications .

Can anyone understand what might 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]; 
+7
source share
6 answers

Your code seems good.

Try cleaning the project, uninstall the application from your device / simulator, and then reinstall it. That might help :)

+3
source

I donโ€™t know the reason (and I didnโ€™t read the documentation either), I just turned on the action notification setHasAction:YES property and the sound started to play.

+2
source

make sure the iPhone is not in silent mode (because your code seems good)

just check the button on the side of your iPhone

0
source

Ok, thatโ€™s what happened. I forgot how the application handles the notification itself if it still works. My code showed only UIAlertView and did not play sound. I'm not sure why it worked with standard sound. In any case, I added this code to my AppDelegate:

 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { NSLog(@"didReceiveLocalNotification"); if (application.applicationState == UIApplicationStateActive) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"MarkMyTime" message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:notification.soundName ofType:nil]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath]; AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil]; [fileURL release]; player.delegate = self; [player prepareToPlay]; [player play]; [alertView show]; if (alertView) { [alertView release]; } } } - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag { NSLog(@"Releasing player"); [player release]; } 

This will display the UIAlertView and play the sound on the notification object. You also need to add the AVAudioPlayerDelegate interface to the AppDelegate in order to be able to assign a delegate to the player. I think if you use ARC, this code may be a little simplified.

 @interface AppDelegate : PhoneGapDelegate <AVAudioPlayerDelegate> { 

I am not sure if this is the best approach, so feel free to make any improvements.

0
source

Perhaps you are not adding a sound file (* .caf) to your Xcode project: phase assembly / copying package resources.

0
source

your code is good, but check your iphone settings settings โ†’ Notification Center โ†’ Your application โ†’ Sound โ†’ "On" The sound should be "On"

So, to enable this, we tested Inter App Audio on Capabilities in the target applications, and these were the Off capabilities in Inter-app audio, change it to On

then the local notification sound works in inshallah :)

0
source

All Articles