iOS Question Custom sound on remote notification

Nicolás Cieri

Active Member
Licensed User
Hello, could someone explain to me why this code works on some iPhones and not in others?
In foreground it always works perfect (in all iphones), but in background, it only works in some.

Am I doing something wrong?

In those that does not work, the notification is not even visible.

Thanks,

B4X:
Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)

                Dim nm As String = Message.Get("nm")
                Dim n As Notification
                n.Initialize(DateTime.Now)
                Dim no As NativeObject = n
                n.PlaySound = True
                n.AlertBody = nm 
                If App.OSVersion >= 8.2 Then
                    no.SetField("alertTitle", "Alert")
                    'Custom sound
                    no.SetField("soundName", "csound.wav")
                End If
               
                spp.myPhone.Vibrate
               
                MediaPlayer1.Initialize(File.DirAssets,"csound.mp3","")
                MediaPlayer1.Looping=False
                MediaPlayer1.Volume=1
                MediaPlayer1.Position=0
                MediaPlayer1.Play
                NativeMe.RunMethod("register", Null)
                n.Register

                CompletionHandler.Complete
               
End Sub
 
Last edited:

Nicolás Cieri

Active Member
Licensed User
Ok, after many attempts, I realized that the "silent notification" only works if the device is wn Wifi or in Foreground. That is why I cannot play in "background" when on 4G.


If the notification is not silent, that is, I do it normal.

So if I receive the notification in the background regardless of whether I am on Wifi or 4G, the problem then is that the "Custom Sound" does not respect me.

The notification is received with the normal sound, and the mediaplayer runs until the application is opened.

Is there a way to change the remote notification sound?

Put a custom sound? I have done the tests in sending the "sound" parameter, but I can't make it change the default sound.


This post only works for local notifications.
 
Upvote 0
Top