I recently started working on my game using Firebase and considering what Firebase offers is pretty much all I need, at one place. But now i'm facing few limitations/implementation issues so any help would be appreciated.
I'm developing a semi-online game which will allow users to play as long as no network is available and sync with Firebase soon as it gets connected. For very first launch connection is mandatory as i've to pull configuration data from Firebase and later user can play with offline saved state which will be pushed later whenever connected.
I'm quite noob to Firebase so pardon me if I misunderstood any implementation. I looked over different answers and mostly were in respect to native Android/iOS, not for Unity. So either I wasn't able to find my answer or it was asked years ago but still not answered. Thanks!
Disk persistence for the Realtime Database is now available since version 5.4.0 of the Firebase SDK for Unity. See the documentation for FirebaseDatabase. SetPersistenceEnabled() and the release notes for that version.
Old question but still hard to find a correct answer.
Firebase documentation is definitively ambiguous : on this page :
https://firebase.google.com/docs/database/unity/start
First lines :
"The Firebase Realtime Database stores and synchronizes data with our NoSQL cloud database. Data is synced across all clients in realtime, and remains available when your app goes offline."
Unity Firebase does not support real offline capabilities.
It will work only if your game starts with a network ON, and while playing, if the player has network OFF, it will go on correctly as long as you have the network ON before stopping the game ! so it can synchronize.. otherwise all changes are lost !
Here is a answer coming from the firebase support on this problem :
Currently, Unity doesn't support offline capability. Apologies about this. This is indeed something we're looking into, however, I cannot guarantee that this will be available anytime soon. We'll keep your feedback in consideration moving forward.
The documentation is explaining that your app will continue to save your data while offline. When data is written, it's written to this local version first and synchronizes that data to the server once connectivity is reestablished. Check here for more details. For additional context, Firebase's network resilience will work on Unity. So as long as the app stays active, Firebase will continue functioning if the network connection drops. In that case it serves any reads from its cache and keeps a queue of pending writes. But currently there is no support for disk persistence, which would allow the cache and queue to survive during app restarts.
I activated
FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(true);
during initialization of my game.
It works fine in iOS but it does not work in Android.
Related
I came across a wonderful feature of Firebase offline feature. I integrated that in my app just by writing one line of code in my main.dart file after initializing Firebase await FirebaseDatabase.instance.setPersistenceEnabled(true);
Question 1 :
I couldn't able to understand the database.keepSynced(true) function because without using this line of code, my app is persisting old as well as fetching new updated data, so what this exactly does ?
Question 2 :
How could I prevent the write operations when a user is offline, because I read that after setting persistence enabled, it makes a queues of write operations and update them when user gets online, so how could I stop this ?
Question 3 :
Is this persistence feature going to work in IOS device as well or need some permission settings first ?
Thanks
When you call FirebaseDatabase.instance.setPersistenceEnabled(true) you're allowing Firebase to create a local file on the device where it persists any data it's recently read, and all writes that are pending while the device is offline.
When you call keepSynced(true) on a node, you are telling the SDK to always keep that node synchronized. It essentially creates a onValue listener on the node without any handler code, so you're purely doing this to keep the data synchronized for when the device does go offline.
By combining keepSynced(true) with setPersistenceEnabled(true), you're specifying that you want the app to continue working when it's offline across restarts, and which data is needed for that.
If you call keepSynced(true) on the root of your database, you're telling the SDK to synchronize all data in the database to the disk cache. While this may initially be a quick way to get offline mode for your app working, it typically won't scale when you more people start using your app.
If you only want to allow write operations while the client has a connection to the database backend, you can register a local listener to the .info/connected node, which is a true value when there is a connection and false otherwise.
Note that Firebase doesn't require this, as it queues the pending writes and executes them when the connection is restored. In general, I'd recommend working with the system here instead of against it, and also trying to make your app work gracefully in the offline scenario. In many cases there is no need to disable functionality while the app is offline.
Offline disk persistence is available on Android and iOS, but not on web.
I am working with electron js and angular. And I want to use firestore database.
As far as I know, firestore is enabled with auto persistency.
First of all, will it work with my desktop application (node base / electron + angular)?
Second, let's say my application mostly works offline. And I need to do certain CRUD operations during these uncertain offline runtimes. So, if the first question's answer is yes, can I perform above operations in offline mode and will it sync as soon as the system goes online?
Third and last, if the answer to the second question is yes, then what if my system shutdowns that is desktop?
I will be glad for a detailed explanation of answers and a detailed explanation of how persistence works and is provided.
I am new to this channel. Please don't mind if I ask my question informally.
Firebase saves all offline actions to essentially an internal transaction pool for offline persistence. When Firebase does connect back online, it will attempt to sync all previous changes including transactions, document updates, and deletes.
The issue is the local pool wasn't made for extended offline use and over time, depending on how much data, it can slow the app down to handle all the data.
I've heard it should behave fine if the device is offline for about a month or two for general use but it might be better to support your offline app with an offline-first database such as PouchDB or NeDB and sync changes with Firebase as needed.
Using
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Is this guarantee to download the data only one time across the App life/App restarts even if the user has good connection?
N.B: The official docs isn't clear ( at least for me) at this point.
By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache. Listener callbacks will continue to fire for local updates.
The sole goal of enabling persistence is to ensure that the app continues to work, even when the user starts it when they don't have a connection to the Firebase servers.
The client does send tree of hash values of its restored local state to the server when it connects, which the server then uses to only send the modified segments back. But there is no guarantee on how much data this sends or saves.
If you want to learn more about what Firebase actually does under the hood, I highly recommend enabling debug logging and studying its output on logcat.
For more on the topic, see these questions on Firebase's synchronization strategy.
I am building a flutter app with cloud firestore and I am using the offline capabilities.
When coming back online after I made changes offline, it seems like the changes take quite some time to synchronise (sometime up to a minute).
Is there any ways to force the synchronisation manually so that I can could trigger it myself when listening for the device to get back online?
Thanks a lot for your help!
The native SDKs for iOS, Android, and Web have API calls that allow you to explicitly manage connection state. While those are not explicitly made for your use-case, it'd be worth a try to see if disabling/re-enabling the network in short succession makes a difference.
Unfortunately those methods are currently not wrapped in the Firestore class of the FlutterFire library.
There is an open issue in the Github repo to track demand and progress on it. I just gave it an upvote.
I have built an application with Firebase and I've also made a desktop version available with nw.js. The point of this being to allow for better offline usage in areas with bad or no internet (and it will sync when the user gets internet again). Now, I can disconnect just fine and reconnect while the app is running, but I want to be able to fully close and reload the application. I've seen this blog post from firebase, but it appears this only works for mobile platforms.
Is this currently possible on the web platform, too?
All Firebase SDKs will handle intermittent loss of connectivity (driving through a tunnel). But disk based persistence, which allows the data to survive an app restart, is currently only available in Firebase's iOS and Android SDKs.