'Best way to add a core data entry every day?

so I have an app to keep track of ones expenses. These are represented by instances of a "Expense" Core Data entity.

I want be able to mark certain expenses as repeating so they are added automatically daily, weekly, monthly etc. However, code can't be run when the app is closed, so an "Expense" instance can't be created at this very moment.

Here are some approaches and my thoughts why I think won't work very well.

  1. At app launch, check the current date and the date of the expense set to repeat e.g. every day. However this only works when the user launches the app at least once a day.

  2. Check at app launch, if there are enough repeating expenses created since the last launch of the app. For example: I have an expense dated May 1 set as reoccurring daily. Next app launch is on May 4. The system sees there are not enough repeating expenses created yet so it adds one for May 2, one for May 3 and one for May 4. However, when the user deletes such a repeating expenses it gets recreated every time the app launches.

  3. Push notifications: As far as I understand, code can only be run if the user reacts to the notification which is not guaranteed.

  4. Background Tasks API: I could write some code to check if there need to be create one repeating expense while utilizing the Background Tasks API, however am I really guaranteed that this code gets executed at least once a day?

Any suggestion how to approach this? Thanks!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source