iOS Question Firebase has stopped working.

davemorris

Active Member
Licensed User
Longtime User
Hi Guys
I have a iOS app which receives Firebase messages and in the last month it has stopped working.
This is what I have tried.
1. I am using the latest version of B4i (v5.80)
2. The Android version of the App is still working ok.
3. Using the post https://www.b4x.com/android/forum/threads/firebase-facebook-v2-0-july-2019.107435/#content updated the internal library.
4. To eliminate my sender software, I have tested by using the FireBase console to send messages directly to the phone but with no success.

Is anybody else having problems with Firebase operation (or is it just me)?

p.s. It may help by pointing out that few weeks ago my iOS Distribution Certificate expired, so I renewed all the certificates (to bring everything in line) - I am wondering if this is the problem, but without an error report I have no idea.

Kind regards
Dave
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I have tested by using the FireBase console to send messages directly to the phone but with no success.
Never test with the console. Only with the B4J code.

What is the output of the B4J tool?

What is the output of this code:
B4X:
Sub Application_PushToken (Success As Boolean, Token() As Byte)
   Log($"PushToken: ${Success}"$)
   Log(LastException)
End Sub
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi, Erel (an update)

I think my Firebase operation maybe a bit rusty - so I decided to start with your original B4A firebase tutorial
https://www.b4x.com/android/forum/t...s-firebase-cloud-messaging-fcm.67716/#content
and them move onto the B4I version.

However, I have a problem (would you believe) with B4A tutorial - To avoid moving off topic I have raised another topic (in the B4A section) and intend to continue this topic later.
Please see my B4A topic https://www.b4x.com/android/forum/threads/problem-with-b4a-firebase-tutorial.108183/

Regards
Dave
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi Erel

Back on the B4i tutorial - I have run it up according the tutorial - the B4i code compiled and installed on the iPhone (and it asked for permission for notifications).

Run up the B4J (the version with topic = "ios_general")

B4J log as requested.
---------------------
Waiting for debugger to connect...
Program started.
[jobname=fcm, success=true, username=
, password=, errormessage=, target=class b4j.example.main
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@b8f8f4, response=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpResponse@1b0f6b2
, tag=java.lang.Object@d1f1c8, main=null, httputils2service=null
]
{"message_id":5691122656269300546}
---------------------

The iphone log was
---------------------
Application_Start
Application_Pushtoken
PushToken: 1
<B4IExceptionWrapper: (null)>
Application_Active
FCMConnected
------------------------

However, the Application_PushToken() code appeared not to run - so nothing in the Log.

Kind regards
Dave
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi, Erel
Thanks for response.
your quote "Why? You can see it in the logs." - I must be missing something, all I can see it is not receiving the notification.

Anyway - checking the code it appears both sides have the correct topic - see below.

B4X:
#ApplicationLabel: TestPush
#Entitlement: <key>aps-environment</key><string>production</string>
'use the distribution certificate

'use the provision profile that goes with the explicit App Id
#ProvisionFile: FirebaseTestdm.mobileprovision
Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private analytics As FirebaseAnalytics
    Private fm As FirebaseMessaging
End Sub

Private Sub Application_Start (Nav As NavigationController)
    analytics.Initialize
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    App.RegisterUserNotifications(True, True, True)
    App.RegisterForRemoteNotifications
    fm.Initialize("fm")
End Sub

Private Sub fm_FCMConnected
    Log("FCMConnected")
    'here we can subscribe and unsubscribe from topics
    fm.SubscribeToTopic("ios_general") 'add ios_ prefix to all topics
End Sub

Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
    Log($"Message arrived: ${Message}"$)
    Msgbox(Message, "Push message!")
    CompletionHandler.Complete
End Sub

Private Sub Application_Active
    fm.FCMConnect 'should be called from Application_Active
End Sub

Private Sub Application_Background
    fm.FCMDisconnect 'should be called from Application_Background
End Sub

Sub Application_PushToken (Success As Boolean, Token() As Byte)
    Log($"PushToken: ${Success}"$)
    Log(LastException)
End Sub

And for the B4j (I have removed the API_KEY - no sure it should be seen an a public forum - will send a email if you need it)

B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private const API_KEY As String = " REMOVED "
End Sub

Sub AppStart (Args() As String)
    SendMessage("ios_general", "title", "body")
    StartMessageLoop
End Sub

Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    If Topic.StartsWith("ios_") Then
        Dim iosalert As Map =  CreateMap("title": Title, "body": Body, "sound": "default")
        m.Put("notification", iosalert)
        m.Put("priority", 10)
    End If
    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

Kind regards
Dave
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
PushToken event is raised when the push token is received. It is not the same as Application_RemoteNotification which is raised when a message is received while the app is in the foreground.

Everything looks configured properly. Maybe you are sending with the wrong server key? Maybe it belongs to a different Firebase project?
Have you replaces the distribution push key in Firebase?
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi, Erel
I missed that, the API_KEY was wrong - when corrected it worked!

Sorry to waste you time (I should have checked the details)

Kind regards
Dave
 
Upvote 0
Top