I am writing an Android/Cordova/Firebase app which needs to work offline. I have data objects which are updated; I simply update them and use Firebase Database's offline features so that they are uploaded when the app comes back online. That works fine. The problem is that the items also involve blobs which I need to upload to Firebase Storage. I want to somehow be alerted when a pending update is sent to the server, so that I can initiate the upload to Firebase Storage.
Of course I can manage the online/offline status myself with a queue of pending Firebase Storage uploads, but is there any way to have Firebase tell me when a pending update to the database has been made?
There is nothing built into the Firebase SDK to signal when it is completely in sync with the server. In the past I've recommended writing a dummy value from the client when it's back online and having a listener that wait for that dummy value to show up. Once you get that dummy value, you're guaranteed to have also received updates that were written before it.
Related
I am using firebase and having an issue that I am not able to check wether my offline data has uploaded to firebase server or not. Is there any way to check this with and without internet connection?
Because Firebase reference.setinfo firstly saves the data locally and then on the server.
Database.database().isPersistenceEnabled will do it for us, but in some conditions when the data saved locally is in a large amount then the risk to loose users data will increase.
We want to logout the user and also want to make sure that all of its data will be saved on the firebase server.
Any Firebase Database writes are locally persisted if the call completes. If they ever fail, it raises an exception.
To know if the write was persisted to the server, use a completion block as shown here: https://firebase.google.com/docs/database/ios/read-and-write#add_a_completion_block.
I'm trying to figure out where users of my app lose interest during the onboarding process. To that end, I've implemented Firebase Analytics. However, it seems that in the scenario where the user only uses the app once never to open it again, the collated analytics data are never uploaded to Firebase. Only when the app is launched a second time, the data are being uploaded.
Does Firebase Analytics have a means of forcing the uploaded upon app backgrounding?
There is no way to force the Firebase Analytics client to send its data to the server at any specific time.
But as Todd says in his blog post How Long Does it Take for My Firebase Analytics Data to Show Up?:
On iOS devices, Firebase will also send down data when your app moves into the background. So if a user tries your app for 20 minutes and then uninstalls it, that session data will still be received, because your app will have sent down the data the moment the user moved your app to the background.
The only caveat to this:
The one corner case where analytics data would actually get lost on iOS would be if your app crashed and then your user immediately uninstalled it.
So it looks like the analytics data should be sent to the server if the user background the app. If that doesn't happen for you, can you describe the flow of your users whose data is not showing up more explicitly?
I have a fully functioning application that uses Firebase as a backend. I want to be able to have a user receive a notification when a child is added to my Firebase database under that users ID.
I have looked everywhere but all I can find are links to OneSignal or people telling me to "make a custom server" as if it can be done by magic. How do I go about making a server? What language? What do I do with OneSignal? Can someone guide me step by step without telling me to simple make a custom server.
I believe Cloud Functions for Firebase is exactly what you're looking for. Specifically, Realtime Database Triggers:
The Realtime Database supports the onWrite() event, which triggers anytime data is created, destroyed, or changed in a specified database location.
In a typical lifecycle, a Firebase Realtime Database function does the following:
Waits for changes to a particular database location for write events.
Fires when a write event occurs and performs its tasks (see What can I do with Cloud Functions? for examples of use cases).
Receives an event data object that contains two snapshots of the data stored at the specified path: one with the original data prior to the change, and one with the new data.
And going through the What can I do with Cloud Functions?, theres Notifying users:
Notify users when something interesting happens
Developers can use Cloud Functions to keep users engaged and up to date with relevant information about an app. Consider, for example, an app that allows users to follow one another's activities in the app. In such an app, a function triggered by Realtime Database writes to store new followers could create Firebase Cloud Messaging (FCM) notifications to let the appropriate users know that they have gained new followers.
The function triggers on writes to the Realtime Database path where followers are stored.
The function composes a message to send via FCM.
FCM sends the notification message to the user's device.
To review working code, see Send FCM notifications.
Other interesting notification use cases
Send confirmation emails to users subscribing/unsubscribing to a newsletter.
Send a welcome email when a user completes signup.
Send an SMS confirmation when a user creates a new account.
I want to store only 20 Notifications which include
"Title,Detail and Received Time" fields inside Notifications Table.But,I only found solution for working CoreData with CRUD some example.But,I am still seeking for working with limitation when user fetch new results from api inside device database.That is where I am stuck.I don't know how to do it using CoreData because I was beginner at that.
Requirement :
1.Application can only store 20 Records maximum.So,when it reach max length,it will do First-In-Last-Out to Notifications table base on Notifications Received Time.(First Problem)
2.Every time the user do pull to refresh,my app fetch new notification from Web-Backend and replace or overwrite on user device database when it successfully download new notifications like "Push Notification Service App" on App Store.(Second Problem)
I really need a hand to pick up with core data flow which I am stucking at things I am not familiar with.
Any help or guide please?(Posting Sample with .json is appreciated)
use NSUserDefaults for that if your data size is small
Consider using a service, like RestKit or similar, to support your web service interaction. Each record should have a unique identifier supplied by the server so you can find an existing copy and update it instead of needing to delete everything and recreated it.
To trim your data use a fetch request with a fetchOffset and a sortDescriptors by date. This allows you to skip the newest 20 items and gives you a list of everything that needs to be deleted. If you're using RestKit you can supply this fetch request in a fetch request block and the deletion will be done for you.
I build apps that bundle up JSON data. I want to switch to Firebase as my backend, but I need to ensure I can access the data even if firebase is offline. There's no guarantee that the user will have an internet connection at the time they launch the app. The data consists of a fairly large JSON blob.
I heard that firebase does cache data on iOS for offline access, and that's great. I just need to know how to bundle the data for that first time the app is ran, so the user can use the app prior to getting to a network connection.
As it sounds like you discovered, the Firebase Obj-C client does have beta support for offline access / disk persistence. Details can be found here.
But that doesn't address your desire to "seed" the app with initial data so that it has data available before the app has ever been able to connect to Firebase. Unfortunately, there's no direct support for that.
One hacky solution you could attempt with Firebase is to just do a setValue with the data in question, in order to seed the cache. This should work but will eventually try to write that data to Firebase, when the app gets connected, so you'd probably want to have security rules to prevent the user from actually modifying that data. As I said, it'd be a hacky solution.
For now it might be best to just handle this with special logic in your app that pulls data from some other data source (hardcoded values or an embedded file or whatever) until the first time you get data from Firebase.
Sorry there's no direct support for this at the moment. We'll take a look to see if we could support this more directly in the future.