iOS Question Firebase has stopped working.

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

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

    Code:
    #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(
    TrueTrueTrue)
        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)

    Code:
    '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
     
  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
    Dave
     
Loading...
  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