This is driving me nuts, I believe I have tried every possible approach by now, but my phone still decides to stay silent. I just want it to play any sound for now when I present a local notification. Currently, neither the UILocalNotificationDefaultSoundName
nor the custom sounds that I added to my app bundle are working. I wrote a simple countdown app that uses presentLocalNotification:
when the count down is finished.
- (void)showLocalNotification
{
UILocalNotification *alarmNotification = [[UILocalNotification alloc] init];
alarmNotification.alertBody = [NSString stringWithFormat:@"fired at: %@", [NSDate date]];
alarmNotification.soundName = UILocalNotificationDefaultSoundName;
// alarmNotification.soundName = @"glass.aiff"; // "glass.aiff" is a file in my application bundle
[[UIApplication sharedApplication] presentLocalNotificationNow:alarmNotification];
}
I also show a UIAlertView
that will be initialized and displayed from the AppDelegate
when the notification is received:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Local notification was received" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
The local notification is received and the alert is shown, in the notification center I can also see that the notification has been fired, only the sound is not working...
I checked every similar question on stack overflow, enabled all my sound settings, made sure that in the Settins of the phone notifications for the app are enabled, I even received push notifications from other apps while I was testing where the sound has been played...
What the hell am I missing that my phone doesn't play any sound? Do I have to import some framework or call anything else on the notification when I fire it or when it is received?
Maybe the easiest solution would be if someone would post a minimal version of the code that is needed to play the default sound when a notification is presented (although I believe I already wrote that minimal version myself - except that it doesn't work).
By the way, I tried the app both on a real device and in the simulator, none of which worked...