2

This is the code I have in my AppDelegate.swift

func applicationWillTerminate(_ application: UIApplication) {
        FirebaseEventHandler.Instance.endSessionDataSave()
        print("test3")
    }

This is the code I have in FirebaseEventHandler.swift

func endSessionDataSave()
    {
        if(guideToGalaxy != 0)
        {
            print("test1")
            eventCatch(eventName: "theAnswerTo", parameterName: "Life_Universe_Everything", parameterValue: 42)
            print("test2")
        }
func eventCatch(eventName: String, parameterName: String, parameterValue: Int)
    {
        Analytics.logEvent(eventName, parameters: [
            parameterName: parameterValue as NSObject
            ])
    }
  • I will get test1, test2, and test3 in my output
  • In following the breakpoints, I can clearly see that the program is walking through all of the code
  • The event will not show up in Firebase though

Any ideas as to why I am not receiving this data in Firebase? I was thinking there might a delay in the sending of information to Firebase, and that the app just terminates too quickly, but I have no way of knowing this...

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jonesy
  • 23
  • 2
  • 1
    Likely because the App terminates so threads that would make API calls to Firebase aren't being sent. – COSMO BAKER May 22 '19 at 20:53
  • 3
    You should save data when the app enters the background, not when it is terminated. And note that `applicationWillTerminate` is not called in many cases so don't rely on it. – rmaddy May 22 '19 at 21:03
  • 1
    My goal is to record the duration of time a user spends in a certain setting. Additionally, these settings are still active in the background, so recording every time someone goes into the background would totally skew the data. Is there another way to get this data only when the app is about to terminate (again, it is getting called, but the data just isn't sending)? – Jonesy May 23 '19 at 21:04

0 Answers0