Wednesday, January 22, 2014

Sounds and notifications

If you are developing iOS application, with service that requires notifying users at specific time (e.g. alarms or utility applications like Power Nap), there are lot of specific issues regarding sounds, that you should be aware of. Setting custom notification sound is straightforward via soundName property of UILocalNotification object:
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.soundName = @"melody.aiff";
1. The sound files must be in the main bundle of the client application. You can't use URLs e.g. from your iPod library to set custom sound. If your app still provide notifications with default sounds, you should check if the sound file is in the root directory of application project.

2. You can't set different system sound for notification. Either you don't specify sound, and notification sound will be default, or set sound from application bundle.

3. The sound must be aiff, wav, or caf file. You can't add .mp3 sounds for notification sound.

4. On iOS 7 it's possible that notification sound is off by default. 


One of the solutions mentions removing all code in your app that operates with applicationIconBadgeNumber. Now, your application should have notification sounds turned on by default, but you can test it only with new device, where you didn't previously install app.

5. If user switches phone to silent mode, notification sound will also be silent. In that case, there is no way to play sound when your app is in background.

6. Without explicit code, notification banner (with sound) will not show, when application is active (iOS 7). You can add code to display banner, or you could present custom view and play sound from application. This will work even if the phone is in silent mode.