Apple Ramos
Apple Ramos

Reputation: 275

Background timer in swift

I am trying to make a system in which my app will add a gem every 30 minutes. I would also want it to run in background so that when the user terminated the app, the gem will still spawn every 30 minutes.

I don't know where to start and what to use. So please help, thanks in advance.

Upvotes: 0

Views: 726

Answers (1)

Paulw11
Paulw11

Reputation: 114773

Executing in the background on iOS is problematic - There are specific background modes for services like location and Bluetooth but no general purpose background execution.

Probably the simplest approach is to store a timestamp in NSUserDefaults when the last gem was spawned. Then, when the app is relaunched you can compare the current time with this timestamp and calculate how many additional gems should be awarded.

Upvotes: 1

Related Questions