Reputation: 35
I'm implementing an app for iOS that is based on events. These events have a startTime and endTime. They are available to the user to see only at this interval from startTime to endTime. That's how it works: An user can create an event and post it to the Firebase database (the event contains startTime and endTime). So if the current time matches this interval, the user can see the current events that are going on; but if the endTime arrives, the event gets deleted from the database and the user can no longer access it.
The thing is I know nothing about javascript and how it could work on an iOS app with Firebase. I think (through my research) that I need something to check the database for old events and I have no idea how to implement it.
How does this check works on an iOS app with Firebase? I'm sorry if I wasn't clear
Upvotes: 1
Views: 2138
Reputation: 2525
The accepted answer is ok but you do have a "proper" option.
You can use Google App Engine and write a backend which runs a script say every X hours to clear out old entries (be careful with TZs in your timestamps, make sure everything is consistent). Depending on whether you feel you will have other processing needs in the future, it may be worth going that route as otherwise you are rather limited with what you can do (it all need to go through the client apps, and you have security, reliability and performance issues potentially depending on your use case).
For that you would need a full Google App Engine (Google Cloud) account and probably higher pay-as-you-use pricing.
For details how to approach this see here: https://cloud.google.com/solutions/mobile/firebase-app-engine-android-studio
From there you can also see the nice design option diagrams they've done to visualize how your client apps + firebase + app engine work together. https://cloud.google.com/solutions/mobile/mobile-app-backend-services
You should still implement client-side filtering of events since the purging of old events won't be done in real time.
BTW Google literally JUST NOW uploaded fancy new tutorials (codelabs) replacing all of firebase's old docs. So I suspect they will very soon add a codelab with app engine integration as well (I couldn't find one yet). In the meantime, you can see the one I pasted above, it is from google's official cloud site.
Best of luck.
Upvotes: 3
Reputation: 263
I've had to implement something similar. Here's the breakdown of how you can achieve this with Firebase.
Firebase does not provide server-side logic so you can't rely on Firebase deleting the data for you (in the case the event owner terminating the app, turning off phone, etc).
Use FirebaseServerValue.timestamp
to provide your event with a standard time value. This will be your constant to either allow or deny a user from seeing an event.
Use if / else
statements to control the event's visibility only between startTime
and endTime
(also set as timestamps).
Because you can't use server side logic to delete the data, you must use the client to remove data from Firebase. Use the if / else
logic from #3 to determine if your current timestamp value is past the endTime
timestamp, and, if true, remove that piece of data from Firebase.
Hope this helps.
Upvotes: 1