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
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
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
UserDefaults
)UserDefaults