Public Sub SendMessageTo(Devices As List, msg As Map)
Try
'Sammeln der tokens, an die die Nachrichte gesendet werden soll:
Dim sb As StringBuilder
sb.Initialize
For Each t As String In Devices
sb.Append($"'${t}' in topics ||"$)
Next
sb.Remove(sb.Length-3, sb.Length) 'will fail if topics is empty
Dim m As Map = CreateMap("condition": sb.ToString)
Dim Job As HttpJob
Job.Initialize("fcm", Me)
m.Put("data", msg)
If msg.get("steuerbefehl")<>"" Then
m.Put("priority", 10)
m.Put("content_available", False)
Else
Dim notifytitle As String
notifytitle=msg.Get("absender")
'Für Nichtsteuerbefehle und Schlagzeilen wird eine RemoteNotication vom Server ohne Ton gesendet.
Dim iosalert As Map = CreateMap("title": notifytitle, "body": "neue Informationen")
m.Put("notification", iosalert)
m.Put("priority", 10)
m.Put("content_available", True)
End If
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=" & Main.FirebasePushApiKey)
Catch
Main.Logger.logsFATAL(LastException.Message)
End Try
End Sub
Sub JobDone(job As HttpJob)
If job.Success=False Then
Main.Logger.logsInfo("iOS-Geraet(e) konnten nicht gepusht werden! " & job.ErrorMessage)
End If
job.Release
End Sub