iOS Question [Solved] Problem with silent push and firebase

schimanski

Well-Known Member
Licensed User
Longtime User
I have changed my ios-app to firebase-push service and I'm using silent push and fetch download. I understood the silent-push, that the
B4X:
Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
is also raised, when the app is in the background and not killed from the user over the taskmanager.

But I have now mentioned, that my app doesn't receive silent-push messages, when it is in the background. For some times (not always), it is possible to send a push for max one minute after the app was set to background, but after that, the app is again not reachable. The app is always in the user-list.

After activating the app, every push-message arrives, so that no message is lost.

Im using the

B4X:
#PlistExtra: <key>UIBackgroundModes</key><array><string>fetch</string><string>remote-notification</string></array>

and the newest main-file from fetch-download.

Is it possible, that apple changed something in the last updates?

I have also checked it with the releaselogger, but no result...

Edit: If i call fm.fcmdisconnected in application_background, no push will arrive, if the app is in the background. If i don't use fcmdisconnect, i will receive push for a few seconds, i think as long, as the os kills the app. It seems, that with killing the app by os, the fm is disconnected and the firebase-push doesn't launch the app. Under apn, it was no problem...
 
Last edited:

schimanski

Well-Known Member
Licensed User
Longtime User
I only use FCM. Do i have to use both? FCM and APN? I thought, that fcm could replace apn...
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
It is worth testing it with regular notifications and see whether they arrive.

I have tested it with regular notifications and it works normal, the alerts arrived all time.

Before I try to renew all certificates, perhaps someone could take a look at my servercode. Perhaps, i made a mistake:

B4X:
Public Sub SendMessageTo(Devices As List, msg As Map)
    Try
        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, "steuerbefehl": msg.Get("steuerbefehl"), "konferenz": msg.Get("konferenz"), "absender": msg.Get("absender"), "sender": msg.Get("sender"), "filename": msg.Get("filename"), "daten": msg.Get("daten"), "zeitstempel": msg.Get("zeitstempel"), "groesse": msg.Get("groesse"))

        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)
    Catch
        Main.Logger.logsFATAL(LastException.Message)
    End Try
End Sub
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Are you using a local builder? If so, which version of Xcode?

No, I'm using host builder. I have tried

B4X:
m.Put("content_available", True)
,

B4X:
m.Put("content-available", True)
,

removing fetch, removing fetch with
B4X:
m.Put("content-available", 1)
, but always the same problem. The client is not reachable after a short time...:(
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Sorry for the late reply, but I was short of time;).
It works! With the help of Erel and mystic and in succession of the following thread

https://www.b4x.com/android/forum/threads/no-firebase_notifications-while-in-background.72228/
https://www.b4x.com/android/forum/threads/no-firebase_notifications-while-in-background.72228/
i got the firebase-push at work in the background. After renewing all the certs and provision-files from the beginning and with the syntax

B4X:
m.put("content_available", True)

("content-available", 1 doesn't work),

silent-firbase-push works in the background.

Thanks for your efforts!
 
Upvote 0
Top