iOS Question Firebase has stopped working.

Discussion in 'iOS Questions' started by davemorris, Jul 30, 2019.

  1. davemorris

    davemorris Member Licensed 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 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
  2. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Sub Application_PushToken (Success As Boolean, Token() As Byte)
    Log($"PushToken: ${Success}"$)
    End Sub
  3. davemorris

    davemorris Member Licensed User

  4. davemorris

    davemorris Member Licensed 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
    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

  5. davemorris

    davemorris Member Licensed 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

    The iphone log was
    PushToken: 1
    <B4IExceptionWrapper: (null)>

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

    Kind regards
  6. Erel

    Erel Administrator Staff Member Licensed User

    Why? You can see it in the logs.

    Are you sure that you are sending to the correct topic? The device should subscribe to ios_general and you should sent to ios_general.
  7. davemorris

    davemorris Member Licensed 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.

    #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)
        NavControl = Nav
        Page1.Title = 
    "Page 1"
        Page1.RootPanel.Color = 
    End Sub

    Private Sub fm_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!")
    End Sub

    Private Sub Application_Active
    'should be called from Application_Active
    End Sub

    Private Sub Application_Background
    'should be called from Application_Background
    End Sub

    Sub Application_PushToken (Success As Boolean, Token() As Byte)
    Log($"PushToken: ${Success}"$)
    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)

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

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

    Sub AppStart (Args() As String)
    End Sub

    Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    "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")
    "notification", iosalert)
    End If
    "data", data)
    Dim jg As JSONGenerator
    "", jg.ToString)
    "Authorization""key=" & API_KEY)
    End Sub

    Sub JobDone(job As HttpJob)
    If job.Success Then
    End If
    ExitApplication '!
    End Sub
    Kind regards
  8. Erel

    Erel Administrator Staff Member Licensed 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?
  9. davemorris

    davemorris Member Licensed 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
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice