0
votes

I have a Xamarin Form Mobile app for submitting a string data (string userPresent = "online") to Firebase Database whenever user is online/open the app.

The string data will be deleted from the database after user click exit or close the app.

The problem is when user close the internet before closing the app, the string data won't be deleted from the database after they leave.

So is there any solution for this or can Firebase cloud function connect with my app, detect online user, and execute functions when the user lost their connection/go offline?

2

2 Answers

0
votes

You can add a new data at Firebase Database called LastOnlineDateTime for each user and update this value in every 1/5/10 minutes depending on how much accurate data you need.

And in the other hand, if any other user is checking this user status you can find the user status based on property LastOnlineDateTime. If date time is before your interval then you can show this user as online. Or else you can show when was this user online.

In this solution you don't have to worry about your App exit event or internet connection lose.

0
votes

You don't indicate is you use the Realtime Database or Firestore (they are two different DB services).

In both cases you could use the presence system, which is based on the Realtime Database, but which can also be used to add presence to a Cloud Firestore app, by actually using Cloud Functions to keep Realtime Database and Cloud Firestore in sync, see here.