Set sounds for local notifications on iPhone 3G with iOS4

I have successfully assigned local notifications in my application using the following code:

Class cls = NSClassFromString(@"UILocalNotification"); if (cls != nil) { UILocalNotification *notification = [[cls alloc] init]; notification.fireDate = self.alarmNotificationDate; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.alertBody = @"Alarm is due"; notification.alertAction = @"Show Alarm"; notification.soundName = @"alarm.mp3"; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; [notification release]; 

Where self.alarmNotificationDate is assigned by NSDate in another way.

Everything works fine in the simulator, but when I test my reliable old iPhone 3G running iOS4, I get a notification, but only with standard sound.

I tried with various sound files but did not succeed.

Any clue why this might be the case and how to fix it?

thanks

+4
source share
3 answers

UILocalNotification does not support mp3. It only supports the formats and containers indicated on the link page.

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

Since custom alert sounds are played using the iOS system sound, they must be in one of the following audio data formats:

  Linear PCM MA4 (IMA/ADPCM) Β΅Law aLaw 

You can pack the audio data into aiff, wav or caf file.

+6
source

There may be several reasons:

  • Is your sound file included in your kit? (most likely seeing that it works on a simulator)
  • The Apple documentation says that you are not using compressed audio formats. See link here . The reason for this is that the iPhone hardware can only play one compressed audio file at a time, so it is not recommended to use it for an alarm if the user is already listening to a song from iTunes.
+3
source

Did you specify the name of the sound using the same upper / lower encoding in both the file name and the file name?

0
source

All Articles