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?
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
Everytime the app opens, we check the date
If it is the FIRST time the user opens the app, we save the date LOCALLY (UserDefaults)
If not, we need to check if the date is the same day or a different day.
If it is the same day as the saved date, we do nothing
If it is a different day, we will provide the user our reward and then overwrite the date in our local save UserDefaults
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
Related
Example is about groupon.com. As we know it say time left for certain products and counts every second. So I can do it with javascript but server side should I update it through Ajax all products left time attribute every second or how to update it in server without AJAX
Anybody knows?
1) Something should update my products timeLeft on server?
I can't find that something.
Only thing I can do is update them through ajax.
The easiest and best way to do count-downs is client-side. Trying to store and update that kind of information is a huge waste of time, space, and processing.
Basically, your database should have the ending time on it, and that will get sent to the client. Then the client will update every second using javascript:
var timeLeft = product.endTime - currentTime;
Then you can update timeLeft every second.
Im in the need on some advise for a realtime serverside timer that would countdown from say 100 seconds. Reason for serverside timer is no tampering.
currently use delayed job but problem its not realtime i could mimic a timer by creatind job every second, but dirty solution
need to display time in view by getting timer value with ajax call to method that returns servertime on page. Know how to do this just to give idea. reload timer would still countdown correctly even on reload page.
Anyone could advise to get a realtime counter in rails app serverside? I would want to create one or more independant timers i can get a value from in railsapp.
Why don't you just create the record you need, but add a "don't open before" DateTime field you can check to see if it's okay to show it?
This sort of thing is trivial to do, and you can set a timer on the client to count-down in JavaScript, then reload the page with the final data at the appropriate time. If someone is impatient and reloads early, you can compute the number of seconds remaining before it can be shown using simple math:
time_left_in_seconds = record.show_at.to_i - Time.now.to_i
Then all you have to do is show a JavaScript timer for that number of seconds, then trigger a page refresh.
I have a Workflow I have created and deployed to a Sharepoint 2007 farm. When it runs against an item two delay activities I have created fire immediately.
I have setup a callback on the InitializeTimeoutDuration event. Through logs and debug output I can see that it is setting the delay to one hour. However, at the next SP timer job cycle (less than 5 minutes) the events proceeding the Delay activity fire off.
I'm lost here. Any help is greatly appreciated.
Update
Through some digging I was able to determine why this was firing off. Once the workflow started a record gets added to the ScheduledWorkItems table in the SP Content database. However, the "DeliveryDate" on the record is set to the current time while the "Created" date is set to one hour previous. However, the delay I'm using is 2 hours, so neither of these times make sense to me at all. Going to try hardcoding it....
Update 2
Even with a hardcoded duration the times are off. I hardcoded a 2 hour delay in and the "DeliveryDate" is now one hour in the future while the "Created" date is one hour in the past. So at least the difference between them is good.
Update
Well, that's embarrassing... found the problem. I'm posting it in here for others that may make mistakes like I do. First off, I was not correct in my UTC->local conversion. The times on the database were correct. What was not correct was how I was setting the TimeoutDuration:
// WRONG!
delayActivity.TimeoutDuration = new TimeSpan("1:00:00"); // one hour
what I should have been doing:
// RIGHT!
((DelayActivity)sender).TimeoutDuration = new TimeSpan("1:00:00"); // one hour
once I made that change everything else seems to be fine.
Well, that's embarassing... found the problem. I'm posting it in here for others that may make mistakes like I do. First off, I was not correct in my UTC->local conversion. The times on the database were correct. What was not correct was how I was setting the TimeoutDuration:
// WRONG!
delayActivity.TimeoutDuration = new TimeSpan("1:00:00"); // one hour
what I should have been doing:
// RIGHT!
((DelayActivity)sender).TimeoutDuration = new TimeSpan("1:00:00"); // one hour
once I made that change everything else seems to be fine.
I have an app that creates and stores a session with a given start date. The user would create a new work session and when they start it, the current time would get saved to the database. The app needs to count time between the start and end of a work session. However, I need to be able to pause, restart, and continue sessions, so I need to get the date from the database.
Say a user starts at 10:30am on a particular day and continues their work session until 12:30pm. Say they need to close the app for whatever reason and come back to the work session. The session needs to count and show the current elapsed time since the beginning. So, I wanted to make an NSDate object with the start time taken from the database...but I can't. At least, I can't find a way of initializing a Date object with a string or even a set of parameters. I'm sure there's a way to do it, but I can't find one.
Take a look at the dateFromString: method on NSDateFormatter
you can start with the Apple Doc here
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1
could type up examples, but I think the documentation contains some
i am making a application in which user enter a date when he want to see an alert,
i have taken the date and stores in database,and sorted date,what is the best way how we schedule them and how?
please send me Code as well
I am knew in Blackberry
Thanks a lot
Look to class java.util.Timer
method schedule(TimerTask task, Date time)