T
T
Timokins2015-03-29 13:53:24
Objective-C
Timokins, 2015-03-29 13:53:24

How to perform an action at a given time?

Greetings,
a question from newbie,
in which direction to dig in
order to find out how to make "timers" in the application,
which, for example, reset one of the settings once a day,
and add data to another setting once an hour.
A more obvious example, when you use an ability in the game, a timer is turned on that after 20 hours it will be restored, or a bonus is added every day at 02:00.
Is there any built-in functionality for this in the iOS SDK or ... ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
An, 2015-03-29
@timokins

Unfortunately no. But perhaps there are custom implementations of such a sheduler.
In iOS, it is very difficult to work in the background + the application can be unloaded at any time by the user. The most ideal option is to implement similar logic on the server, and using some message queue (rabbit mq there) + remote push notification, notify the client about the occurrence of the event.
But if there are problems with the server, then manually this is done as follows:
1) Determine the date and trigger time
2) Start an NSTimer timer with this date, there is an initWithFireDate method (I don’t remember exactly), specifying the selector (method) to fire
3) when the application goes into the background, stop the timer
4) when the application returns from the background or at startup - check if the current time is more than the scheduled time in point 1. If yes, then execute the expected logic, if not, then perform step 2.
In order for the user not to miss the moment of the event, you can throw / schedule local UILocalNotification notifications - in this case, if the application is in the background, the user will see a push and if this is something important for him, he will launch the application and throw you to point 4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question