We have just mentioned, that no firebase-push message arrives, when the app is in foreground under IOs 11.1.1. No problem with older IOs-Versions. Does anybody have the same problem?
Works fine here. Tested with Firebase and iOS 11.1.
Make sure that the push token is received:
B4X:
Sub Application_PushToken (Success As Boolean, Token() As Byte)
Log($"PushToken: ${Success}"$)
Dim bc As ByteConverter
Log(bc.HexFromBytes(Token))
Log(LastException)
End Sub
I've tested it with the latest beta version (11.2) and it works fine.
You can try to add this sub (it worked in 11.2 without it):
B4X:
Sub Application_PushToken (Success As Boolean, Token() As Byte)
Log($"PushToken: ${Success}"$)
If Success Then
Dim no As NativeObject
no = no.Initialize("FIRMessaging").RunMethod("messaging", Null)
no.SetField("apnsToken", no.ArrayToNSData(Token))
End If
End Sub
Application_PushToken is successfull. The device also gets a real token with
B4X:
Public Sub GetToken As String
Dim no As NativeObject
Dim token As NativeObject = no.Initialize("FIRInstanceID").RunMethod("instanceID", Null).RunMethod("token", Null)
If token.IsInitialized Then Return token.AsString Else Return ""
End Sub
We had downgraded one device back to IOS 11 and after that, the device is pushed again over firebase when the app is in foreground.
Firebase recommended to use a key instead of a certificate. Could this be the problem? I'm using a production-apn-cert which is valid until 01/2018.
I mentioned, that firebase had created a new server-key, but I don't know why. I tried both keys without success:
I renewed the apn-cert and uploaded the production-apn to the firebase-console, but when the app is in forground, the Application_RemoteNotification will not be raised in IOS-Versions higher than 11.1.
I don't use topics. I push the devices over the fcm-tokens. It's a mystery to me...
With the following code i can send push-messages to the client in the background, but not in foreground. In both cases, I got a positiv result, so I think, that the servercode is still correct:
Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Private const API_KEY As String = "AAAA1dUkIp8:APA91bFg0fcQnAfybEZmqbzmJ...."
End Sub
Sub AppStart (Args() As String)
Dim Devices As List
Devices.Initialize2(Array As String("ed737rfB4H...."))
SendMessage(Devices, "title", "body")
StartMessageLoop
End Sub
Private Sub SendMessage(Devices As List, Title As String, Body As String)
Dim Job As HttpJob
Job.Initialize("fcm", Me)
Dim m As Map = CreateMap("registration_ids": Devices)
Dim data As Map = CreateMap("title": Title, "body": Body)
Dim iosalert As Map = CreateMap("title": Title, "body": Body, "sound": "default")
m.Put("notification", iosalert)
m.Put("priority", 10)
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
After I changed back from silent push to push, I forgot to delete the content_available-line. This will cause the system under IOS 11.1.1 and higher not to push...sorry for the circumstances...