Search code examples
iosswifttimerlogicnstimer

How to integrate countdown for auction app in iOS


I am building an app that lets users buy and sell items through the bidding/ auction process. When a user taps on a specific item like a shirt for instance, they will see a countdown of the time remaining to bid on that item. How do i persist the countdown on backend? It seems expensive to persist/update the time remaining for each item, each second to backend (Firebase), and then observe the changes in countdown value to update view. How do apps with auctions like Artsy accomplish this? Thank you!


Solution

  • Why do you need to save the remaining time to the Firebase for each seconds?

    You can just save the expired time to the firebase.
    After you fetch the expired time from the Firebase, you can get the duration in seconds by using:

    // Pseudocode
    durationBeforeExpired = expiredTime - currentTime
    

    After that you can do some timer animation or whatever you'd like, and this way the Firebase's expired time and device's expired time will always be in sync.