iOS Question Silent FirebaseNotifications

schimanski

Well-Known Member
Licensed User
Longtime User
Does it work? I have made it as Erel said, but the

B4X:
Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)

is raised after the app is in the forground. As long as the app is in the background, it doesn't receive any silent push-messages...

This is my server-code:

B4X:
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)
Dim m As Map = CreateMap("condition": sb.ToString)
      
Dim data As Map = CreateMap("content-available": 1, "key1": msg.Get("value1"), "key2": msg.Get("value2"), "key3": msg.Get("value3"), "key4": msg.Get("value4"), "key5": msg.Get("value5"), "key6": msg.Get("value6"), "key7": msg.Get("value7"), "key8": msg.Get("value8"))

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=" & Main.FirebasePushApiKey)
 
Last edited:
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Solved!
I called
B4X:
 fm.FCMDisconnect 'should be called from Application_Background

in Application_Background.....
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
I haves still not so clear about notifications on iOS. Some questions.

Why do we have to disconnect from FCM while in background if we still want to receive silent notifications?

Whats the purpose of calling CompletionHandler.Complete? Does it has to be called once all operations are done or after notification received ok?

Sometimes even with the app on foreground, after a while, notifications are not received any more. Is this something to do with the certificates?. I do receive notifications, it just mutes out after a random time. I have tried in debug and release mode with same results.

Thanks
FBP
 
Upvote 0

Manolete

Member
Licensed User
Yes. You just need to add the content-available: 1 to the json string and add the remote-notification plist entry.
Hi!
B4i newbie question:
Do you have an example how to add the remote-notification plist entry?
Thanks in advance,
Manuel
 
Upvote 0
Top