iOS Question [Solved]Push not arriving under ios 11 when app is in foreground

schimanski

Well-Known Member
Licensed User
Longtime User
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?

I'm using hosted builder...

Thanks for help..
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
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
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
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:

1.png
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
I think they means the keys in the apple-developer account instead of a certificate:

Screenshot_20171124-162713~2.png


Screenshot_20171124-162343~2.png
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
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...:eek:

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:

B4X:
[jobname=fcm, success=true, username=
, password=, errormessage=, target=class b4j.example.main
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@14caa3f, tag=java.lang.Object@4cee07
, httputils2service=null]
{"multicast_id":6254152878012074647,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1511620422810222%51ea337a51ea337a"}]}

B4X:
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
 
Last edited:
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
I found the wrongdoer:

m.Put("content_available", True)

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...:confused:
 
Upvote 0
Top