iOS Question how can I get the default notification sound to play with media player?

Baris Karadeniz

Active Member
Licensed User
I receive notifications with sound when the app is background. I need to continue same sound when the app is foreground too. So I need to get default notification sound. How can I get the default notification sound and play? Is there any example?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can play system sounds with this code:
B4X:
Sub PlayNotification (id As Int)
   Dim no As NativeObject = Me
   no.RunMethod("playNotification:", Array(id))
End Sub
#if objc
- (void)playNotification:(int)soundId {
   AudioServicesPlaySystemSound(soundId);
}
#end if

The problem is that the ids are considered private API and your application might be rejected (my guess is that it will pass).
You can see the list of sound ids here: http://iphonedevwiki.net/index.php/AudioServices
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
How can I start the Playnotification sub? When I wrote it into the Application_ReceiveLocalNotification sub, I receive an error that missing parameters. Should I write the id (for example 1000 for new-mail.caf) of the sound into the PlayNotification written in the Application_ReceiveLocalNotification sub?

B4X:
Sub Application_ReceiveLocalNotification (LN As Notification)
    'this event will fire if the scheduled notification happend when the app was running
    hd.ToastMessageShow(LN.AlertBody, True)
    PlayNotification ???
End Sub

Sub PlayNotification (id As Int)
   Dim no As NativeObject = Me
   no.RunMethod("playNotification:", Array(id))
End Sub
 
Upvote 0

Baris Karadeniz

Active Member
Licensed User
I wrote "sound id" into the brackets after PlayNotification and it worked. When the app is at foreground, there happens notification sound too. The codes are given below. But the problem is, User may use different notification sound. Than notification sound when the app is background will be different. So I need to know the notification sound which user is using. How can I get the notification sound which user is using?

B4X:
Sub Application_ReceiveLocalNotification (LN As Notification)
    'this event will fire if the scheduled notification happend when the app was running
    hd.ToastMessageShow(LN.AlertBody, True)
    PlayNotification(1007)
End Sub

Sub PlayNotification (id As Int)
   Dim no As NativeObject = Me
   no.RunMethod("playNotification:", Array(id))
End Sub
 
Upvote 0
Top