I am working on an alarm application. When the app is in the background a local notification informs the user that an alarm is ringing and playing a sound. But when the app is already in foreground I do not want the notification sound to play, but a custom sound. I cannot find how to mute the notification sound and as a result both sounds play simultaneously. Any ideas?
UPDATE: I restarted my device and the problem solved. It probably is an iOS bug.
When your app is open and running in the foreground, the default behavior is that the sound is not played and the user doesn’t receive any alert/banner from the OS. You can receive the notification through the following method (in the class that is your AppDelegate):
And from there you can trigger any other method.
From the documentation on UILocalNotification: