-1

I'm making an app where the user can make a post but I want that post to be deleted from the firebase data based on a time set by the user

I've seen some solutions using firebase cloud functions but I couldn't quite see an answer for swift 4.2

Could anyone help me out pleasee?

  • 1
    I would recommend doing this with cloud functions, not with Swift because your app can't manage the database when it is inactive (e.g. your date is some time when the user is not using the app). Cloud functions can trigger whenever you need them to and are much more flexible for this type of work. – Nathan Jul 10 '19 at 17:36
  • There is no client API for Firestore that lets you automatically delete some document after an amount of time. You will have to write application code to figure that out. – Doug Stevenson Jul 10 '19 at 23:42
  • You can easily delete data from Firebase but doing so at a given time will require you to either create a timer in your app or leverage a [cron](https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html) job to fire a cloud function at regular intervals. The cloud function would delete any nodes set for deletion on that interval. So for example, the user could set a child of a node called `delete_me_at_this_time": some_time and the cloud function could delete all parent nodes where that node is set. – Jay Jul 11 '19 at 15:27

1 Answers1

0

If anything you need to be done in the firebase level, then you need a cloud function set up to handle those.

In your case you can store the post data in some posts collection and the time on another and then write a cloud function to delete the post document from the posts collection by the time you already set.

Have a look here

HexaCrop
  • 3,863
  • 2
  • 23
  • 50
  • A cloud function isn't going to solve the question *deleted from the firebase data based on a time set by the user* - note the *based on a time set by the user*. – Jay Jul 11 '19 at 15:24