-1

I'm trying to track when a user's app is about to terminate and send something to firebase when it happens. I looked through the Offline Capabilities documentation and tried using ".info/connected" as well as .onDisconnectSetValue().

I've had success with .onDisconnectSetValue(), but if the iPhone's side button is pressed and the iPhone goes to sleep, it fires and says the user is inactive (and I can't set another value until the user brings the app to the foreground again).

I tried moving .onDisconnectSetValue() to applicationWillTerminate() so it only catches terminations but it doesn't fire when I close the app (I assume because it can't in time)

Is there anything with Firebase that could set a value with the specific instance of the user closing the app?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Wilson Desimini
  • 722
  • 5
  • 10

1 Answers1

0

The Firebase client can detect whether the app is online, with .info/connected and the app can tell the server to perform a specific write once it has gone offline with onDisconnect.

Firebase has no built in functionality for writing to the database when the user is about to close the app. That's something you're more likely to find on the iOS level, such as shown in iOS - detect when application exits and Which Event When i close app in iOS?. Typical lifecycle events on iOS are applicationWillTerminate, and applicationWillResignActive.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • When I try to call .onDisconnect within applicationWillTerminate it doesn’t work. Is it possible to set a Firebase value when the applications’s about to terminate? – Wilson Desimini Mar 03 '19 at 00:26
  • Firebase has no built in functionality for writing to the database when the user is about to close the app. – Frank van Puffelen Mar 03 '19 at 00:30
  • Okay. I have something that uses Firebase messaging to send APNS silent pushes to other devices, and I wanted to make it so the push wouldn’t be sent if the app was inactive on the device, but I’m not sure that could happen now. Thank you for the help. – Wilson Desimini Mar 03 '19 at 03:30