B4J Question Send FCM group notification to both Android and IOS

Pxs

Member
Licensed User
Hello

I've been using a B4J program to send FCM notifications to Android clients.
We're now adding IOS support. Problem is, a notification formatted for android does not show on IOS ( lacks the additional json info) and viceversa (android does not like the additional fields)

For now, we resolved by sending two differently formatted notification request for each trigger (below code is called twice).

Is there a way to format the JSON payload so that both IOS and Android can digest it with a single request?

Code i've been using in B4J:
B4X:
Private Sub SendBroadcastPushNotification(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body)

    If Topic.StartsWith("ios_") Then
        Dim iosalert As Map =  CreateMap("title": Title, "body": Body, "sound": "default")
        m.Put("notification", iosalert)
        m.Put("priority", 10)
    End If
   
    m.Put("data", data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)  
End Sub
 
Top