Getting last update information / Firebase - ios

When working with a database on Firebase, is it possible from within an iOS app to check the date(& time) a document was last updated using some standard API? I mean without implementing my own system to know when it was last time touched.
It would be convenient if there was a field "lastUpdate" time-stamp for instance.

Neither the Firebase Realtime Database nor Cloud Firestore automatically adds a timestamp field to the data for writes.
If you want such a field, you will have to add it yourself, either from the client, or from Cloud Functions.
For a simple example of the latter, which tracks when a node in the database was last modified, see this folder in the functions-samples repo. The main code:
exports.touch = functions.database.ref('/chat/{message}').onWrite(
(change, context) => admin.database().ref('/lastmodified').set(context.timestamp));

Related

Questions about ios14 widgets -- fetching dynamic data from container app

I am mainly just looking for clarification or resources. Let me explain my situation.
I have an app that internally relies on an always-up-to-date database of items. I'd like to show off items that were released close to today's date. I originally thought I'd just query my database and fetch the relevant items from there. So I began the long process of updating target values so the widget could see my classes, etc... But that was such a HEADACHE.
I thought surely there must be a more lightweight method the designers had in mind, so I then read about "app groups" and being able to pass information via saved settings/preferences. So basically when the app runs, you store some data as json and then you can fetch that information in your widget.
But then, to my knowledge, the data won't update unless the user runs the app again. I was hoping I could keep this widget up to date even if the user hasn't used the app in a long time.
What exactly is the process I should be using to achieve this? Are "app groups" basically the only way to do this? Will I just have to accept that I will often times have stale data?

Google Fit get records with history (updates)

Is it possible to get the DataPoints with history like last update date/creation data and original/updated value?
I need to get a user's weights, and sync them with my app, but, I need to know what records have been updated after I made the first get for a specific period (like last 01.01.2020 - 02.02.2020).
My app uses ionic and cordova with the health plugin, but that is not the point of my question. If needed I can write a new plugin to acces the fit data.
This is the existing plugin code to get the data: https://github.com/dariosalvi78/cordova-plugin-health/blob/master/src/android/HealthPlugin.java
It appears that you cannot get the history of the records.

How can I explicitly set the timestamp when I logEvent with Firebase / Google Analytics?

I'm working in Swift with the Firebase analytics framework.
I see the FIRAnalytics header allows one to logEvent:parameters:
In the app I'm working on, we have a wrapper class Tracking that has the same API basically, but will log the same event to multiple analytics services. (Specifically, Adobe, Adjust, and GA)
What we're hoping to do is log these events locally, persist them, do a bit of post-processing on them at some point, then upload them all later, all at once. (Then flush our queue) When we initially log the event, we give it a timestamp.
So is there a way to logEvent:parameters: with FIRAnalytics where we override the timestamp that it probably adds itself within that method call? I'm guessing there's a parameter key-value I could use?
If you're looking to override the default timestamp that Google Analytics for Firebase uses, I don't think that's possible. I think your best bet would be to just create your own my_custom_timestamp field, and then use BigQuery to analyze your events based on that field.

Automatically remove entry from Firebase that is out of date

I have an iOS social app that uses Firebase as the main database to store all the posts with time stamp included
What I want to achieve is to remove anything that is > 10 days old from my database.
Currently, I am checking this with this super inefficient way (The only way I know). Every time the user queries the firebase, I have swift code that also queries the ENTIRE database and delete all entries that is > 10 days old. This works but it is really inefficient...
What you're trying to do is currently best done on a server you control with a job that runs periodically to scan and delete the old items. You can use the admin SDK for that.
You should also have a index on the time field that you're using to determine how old it is, in order to optimize the query that generates the results.

CouchDB and iOS

I need some help with a CouchDB iOS project.
I'm using Apache CouchDB Server and the couchbase-lite iOS Framework.
On my CouchDB I have a template document.
- CouchDB Server
- database
- template
- document 1
- document 2
- ...
My goal is to only synchronise my iPad with this template document to get the latest data which my application needs.
But when I enter some data on my iPad, I want that this data should be pushed only to couchBase Server.
How can I "tell" my application to synchronise only one file and not the entire database with my server and at the end how can I "tell" my application to only push the data that is input from user side ?
More importantly, Do I need two databases on my server? One for the template and a second one for user input data?
If YES, then I just need to know how I can only push my data.
Guidance needed. Thanks.
This is how I solve this:
I tend to add a 'last update' date to all my documents, and store this in a format that means they'll be sorted in time order (epoch or yyymmddhhmmss) both do.
Create a view that uses the update time as a date.
On your client, store the time since you last updated.
When you update, access the view with a startkey parameter set to the last update date.
You can then either use 'include-docs=true' to get the documents as you query the view.
I tend to use 'include-docs=false' though as it means when a lot of documents have been updated I transfer less data in a single query. I then just directly access each document id that the view returns.

Resources