When I should put StartMessageLoop and StopMessageLoop if I am using a For loop to send push message?
B4X:
For Each s1 As String In Subscriber1
SendData(strTopic1, s1)
StartMessageLoop ' <-- Is this correct?
Next
'StartMessageLoop
B4X:
Private Sub SendData(Topic As String, ID As String)
Dim Job As HttpJob
Job.Initialize("fcm", Me)
DateTime.DateFormat = "yyyy-MM-dd hh:mm:ss"
Dim strDate As String = DateTime.Date(DateTime.Now)
Dim msg As Map = CreateMap("to": $"/topics/${Topic&ID}"$)
' Android / iOS
Dim data As Map = CreateMap("title": strTitle, "body": strBody, "content": strContent, "date": strDate)
' iOS
'Dim alert As Map = CreateMap("title": strTitle, "body": strBody, "sound": "default", "badge": 1)
If Topic.StartsWith("ios_") Then
msg.Put("priority", 10)
msg.Put("content_available", True) ' <--- silent push notification
'msg.Put("notification", alert)
End If
msg.Put("data", data)
Dim JG As JSONGenerator
JG.Initialize(msg)
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)
Wait For(Job) JobDone(Job As HttpJob)
If Job.Success Then
Log(" (" & ID & ")" & Job.GetString)
Else
Log(" [Error:" & Job.ErrorMessage & "]")
End If
Job.Release
intSend = intSend + 1
If intSend = Subscriber1.Size Then
Log(" Sent:" & intSend)
SQL1.Close
'Sleep(3000)
StopMessageLoop ' <-- Is this correct?
ExitApplication2(0)
End If
StopMessageLoop ' <-- Is this correct?
End Sub