iOS Question Manage an incoming Firebase message

Vins

Member
Licensed User
Hi everyone,
I noticed that in B4A it is possible to manage an incoming Firebase message in the Sub fm_MessageArrived (Message As RemoteMessage) within the FirebaseMessaging service.
For example, here it is possible to decide whether a given message should be notified or not depending on a parameter.
Example:
B4X:
Sub fm_MessageArrived(Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Log("MESSAGE FROM = "&Message.From)
        '-------------- CONDITION TO SHOW NOTIFICATION --------------
        If Message.GetData.Get("id_company") = Main.id_company Then
            Dim notify As NotificationBuilder
            notify.Initialize
            notify.SmallIcon = "icon"
            notify.AutoCancel = True
            notify.ContentTitle = Message.GetData.Get("title")
            notify.ContentText  = Message.GetData.Get("body")
            notify.Notify(1)
        End If
End Sub
I can't reproduce the same in B4I, or to be more precise, only if the application is running by intervening in the Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler).
If the application is in background mode, all incoming Firebase messages are notified regardless. How can I decide in this case which messages need to be notified and which are not?
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
Why don't you use different topics for different companies ? For example you can create topic company1,company2,company3. In your code, you can register for topics according to companyid. So when you send a specific message to specific topic only those company members will receive.
 
Upvote 0

Vins

Member
Licensed User
The code snippet I wrote earlier is a simplified example of a more complex problem. The inclusion of multiple "topics" per company is not sufficient to solve the problem, because in my case, in addition to having different companies, each company has one or more user profiles enabled to receive firebase messages. So the system should, after receiving the message, check if it is intended for the selected user profile and only then notify it. This is why I was wondering if a way to handle firebase messages was possible.
 
Upvote 0

Vins

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

You can use silent notifications to start your app in the background. The problem is that they are not very reliable.

Yes, in fact I had already tried with silent notifications, but besides being unreliable, they don't work when the app is killed, thus losing the real utility of Firebase messages. I think I will come up with something with "topics" even if it will be impossible to manage the behavior of a message to 100% (for example by inserting it in a SQLite database).

P.S. I edited my first post and entered the "code" tags
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Yes, in fact I had already tried with silent notifications, but besides being unreliable, they don't work when the app is killed, thus losing the real utility of Firebase messages. I think I will come up with something with "topics" even if it will be impossible to manage the behavior of a message to 100% (for example by inserting it in a SQLite database).

P.S. I edited my first post and entered the "code" tags
Why can't you insert to sqlite database? If you use b4j to send messages to different topics, you can also insert them wherever you want.
 
Upvote 0
Top