Hi, we want to make sure our app pauses when the browser/tab becomes inactive (Run in Background = false in player settings). At the same time, we need to refresh our app data if more than 24 hours have elapsed since the last refresh after the app becomes active again.
Is WaitForSecondsRealtime a reliable way to trigger that refresh across mobile and desktop browsers?
That is, if the app is suspended and has a coroutine running that uses yield WaitForSecondsRealtime, does it use an accurate elapsed time once the app resumes?
Actually, you are better off either comparing the device time on enter/exit background or when connected to a network, check a time server just in case the user changed the time settings (or there was a daylight savings time change).
I can’t find anything that tells you the app has become active again. Javascript proved to be unreliable in my extensive testing in this regard, and there is nothing I can find in the Unity documentation that says anything about it.
Tell me if I am wrong, but there are no messages sent if the network becomes available. If not, then to test if the network was active would require regular polling of some kind. That would be more expensive that what I am doing now.
My current strategy works and is sound - I was specifically looking for answers on how WaitForSecondsRealTime behaves. If it factors in the fact that an app may have paused for a number of hours, then I could increase the interval and check 24 hours later.
We are not worried about people mucking around with their system time and will not affect the data they get. Also we provide a button the player can use to refresh anytime. The reason for the timer is to prompt them to refresh. We run a daily, day-of-year quiz (the sever determines which day of year it is) and the player knows to get the current quiz they need to refresh. We want to prompt them to do so.
Yeah sorry, I forgot to consider that this is a WebGL app. You may have to rely on browser events instead, no idea what kind are available though, if any.
You could check time on the server side if you have a way of identifying each client. You could then check the time diff between the current and last message and if too much time has elapsed, notify the app that it needs to synch time.
As to the behaviour of realtime seconds: just test and time it to see if there is any time diff after say 10 minutes in the background.