I use a server to send push-messages to different devices. For iOS-devices, I use the firebase-push-service. Every IOS-device will use the push-token to register to fcm with:
In the following subs, I collect the ios-tokens to send the message to this. Now, after many units changed from android to ios, we mentioned, that it is not possible with this code to send a push to more than 3 devices. Up to 3, the messages are send without problems. More than 3, I get an 'Bad Request' in the Job_done-event. Is it not possible to send a push to multiple devices? For my way, it is better to collect different device-tokens instead of using main-topics...
B4X:
fm.SubscribeToTopic(File.ReadString(File.DirLibrary, "token.dat"))
In the following subs, I collect the ios-tokens to send the message to this. Now, after many units changed from android to ios, we mentioned, that it is not possible with this code to send a push to more than 3 devices. Up to 3, the messages are send without problems. More than 3, I get an 'Bad Request' in the Job_done-event. Is it not possible to send a push to multiple devices? For my way, it is better to collect different device-tokens instead of using main-topics...
B4X:
Case ID.StartsWith("ios:")
ID=ID.Replace("ios:", "")
iosTokens.Add(ID)
If iosTokens.Size > 900 Then CallSubDelayed3(iOSPushFirebase, "SendMessageTo", iosTokens, msg)
B4X:
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