skip to Main Content

I want to reward the user daily in my app, but when the app closes the timer always stops

I’ve tried doing this…

 Timer.scheduledTimer(withTimeInterval: 86400, repeats: true) { _ in
self.points += 100
}

Can you please tell me how to reward the user daily once?

2

Answers


  1. I think you need to call the function in the User Defaults (Store info locally). Here it is useful for calling functions only once like display the onboarding.

    or on your DB you could set the timer there eg lambda functions on AWS

    Login or Signup to reply.
  2. Of course the timer stops; when you close Facebook, does the news feed keep scrolling? No, the answer is no. Especially as third party developers, we have to complete ALL our tasks prior to the data of the app closing. There are functions to keep working for up to ~5min but after that, any relevant data will close.

    https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate

    So, we need to consider how we can get around this. So, what we need to do is

    1. Everytime the app opens, we check the date
    2. If it is the FIRST time the user opens the app, we save the date LOCALLY (UserDefaults)
    3. If not, we need to check if the date is the same day or a different day.
    4. If it is the same day as the saved date, we do nothing
    5. If it is a different day, we will provide the user our reward and then overwrite the date in our local save UserDefaults
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search