Home > Enterprise >  Change The status of user to offline in firestore
Change The status of user to offline in firestore

Time:11-25

I have Taxi App, And I need add when the driver closed the app, the status of the driver changed to offline in firestore

how I can do that? plz explain for me

CodePudding user response:

Firestore has no built-in capability to write something in the database after the client has disconnected.There's a solution but that uses the Firebase Realtime Database and Cloud Functions to store presence information in Firestore too, which is documented here Build presence in Cloud Firestore.Found this blog you can also check this which might help.

Depending on the type of app you're building, you might find it useful to detect which of your users or devices are actively online — otherwise known as detecting "presence."

Cloud Firestore doesn't natively support presence, but you can leverage other Firebase products to build a presence system.

You can refer this stackoverflow thread1 & thread2

CodePudding user response:

While you can easily update your firestore whenever a user opens your app (just add it to a point executed on launch, like before the runApp() part in your main method), there sadly is no guaranteed way to know, if a user closes your app. It could be force closed via task manager etc., robbing you of the ability to detect it. However, firebase offers the following solution to detect presence, see here.

You could also save a timestamp as the isOnline point and let it timeout. You could update it periodically in your app, giving you not a perfect but maybe a good enough idea if a user is online.

  • Related