0

One of my company's app's requirements is a tracking system, where a user can track other nearby users when using our app. So there is a map and user's location (coordinates) will be updating to Firebase so other users can see on their map.

The most important thing is that we don't want sign out/offline users' location data on Firebase (because we want users only to be able to see online nearby users) so I use Firebase's onDisconnectRemoveValue() method to automatically remove disconnected users' data. The method worked great. BUT, if the app goes to the background (or screen is turned off), onDisconnectRemoveValue is fired too, so the data will be deleted (I don't want it to be deleted).

I searched the Internet, found this SO post.

This method is designed that way, I think I cannot do anything about it.

So my question is: If I want to remove a data on Firebase if the user is disconnected (loss internet connection OR app closed/killed), how can I do that?


Additional info: because I want users can updating their location to Firebase even if the App go to the background or device screen is off so I cannot check the connection at the client (can check, but when connection loss detected, cannot send remove data request to Firebase).

shim
  • 9,289
  • 12
  • 69
  • 108
  • You can do this with an onDisconnect handler. See https://firebase.google.com/docs/database/ios/offline-capabilities#section-presence – Frank van Puffelen Mar 13 '18 at 04:21
  • Thanks for comment, but as i said up there, by some magical ways the app lost connection with Firebase when i turn the screen off or press home button (go to background), so the onDisconnect fired which i dont want to – Dang Nguyen Mar 14 '18 at 07:50
  • Sorry about that. It sounds like you have a very app specific definition of when a user is considered active or inactive, in which case Firebase likely has no a built-in primitive to help you detect it. – Frank van Puffelen Mar 14 '18 at 14:46

0 Answers0