iOS Question Strange firebase behavior. Application_RemoteNotification is not called

stephane..blusson

Member
Licensed User
Strange firebase behavior.
When I send a message from IOS using this code,

B4X:
Private Sub SendMessage(Topic As String, data As Map)
    Log("MyTopic ------------> "& Topic)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    
    If Topic.StartsWith("ios_") Then
        m.Put("content_available", True)
        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=" & WebApiKey)
End Sub


it always comes to android. But after a few messages, it is still being sent to android, but not arriving to IOS. From android it is sent to android and several messages to iOS (after which messages stop arriving). Method Application_RemoteNotification is not called.

Moreover, if after the messages stop arriving, I minimize the application and maximize it again, then the next message will come to the IOS too.

If the application is turned on for some time, then ios will be able to receive several messages again.

A very strange problem.
 

stephane..blusson

Member
Licensed User
Hello, Erel!
it always returns message_id.

Right now I have tested sending using the B4J code:

B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private const API_KEY As String = "..."
End Sub

Sub AppStart (Args() As String)
    SendMessage("ios_general", "title", "body")
    StartMessageLoop
End Sub

Private Sub SendMessage(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", "high")
        m.Put("content_available", True)
    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


Sub JobDone(job As HttpJob)
   Log(job)
   If job.Success Then
     Log(job.GetString)
   End If
   job.Release
   ExitApplication '!
End Sub


It still calls the Application_RemoteNotification function several times, and then (after few messages) I can see notification generated by m.Put("notification", iosalert), but the Application_RemoteNotification function is not called.

If I delete this line (m.Put("notification", iosalert)), I get exactly the same problem as from the first message
 
Last edited:
Upvote 0

stephane..blusson

Member
Licensed User
If I add this field, then the behavior does not change. The Application_RemoteNotification function is called several times, and after a certain number of messages it stops being called, although the notifications created by this field are displayed
 
Upvote 0

stephane..blusson

Member
Licensed User
Thanks for the advice
Yes, Tested using ReleaseLogger, the behavior is the same. 4+ messages arrive, and then the Application_RemoteNotification method is not called
 
Upvote 0
Top