Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd a running countup display timer to an iOS app, like the Clock stopwatch?
    primarykey
    data
    text
    <p>I'm working with an app that processes device motion events and updates interface in 5 second increments. I would like to add an indicator to the app that would display the total time the app has been running. It seems that a stopwatch-like counter, like the native iOS Clock app is a reasonable way to count time that the app has been running and display it to the user.</p> <p>What I'm not sure of is the technical implementation of such a stopwatch. Here's what I'm thinking:</p> <ul> <li><p>if I know how long between interface updates, I can add up seconds between events and keep a count of seconds as a local variable. Alternatively, a 0.5 second interval scheduled timer can provide the count.</p></li> <li><p>If I know the start date of the app, I can convert the local variable to date for each interface update using <code>[[NSDate dateWithTimeInterval:(NSTimeInterval) sinceDate:(NSDate *)]</code></p></li> <li><p>I can use a NSDateFormatter with a short time style to convert the updated date to a string using <code>stringFromDate</code> method</p></li> <li><p>The resulting string can be assigned to a label in the interface.</p></li> <li><p>The result is that the stopwatch is updated for each "tick" of the app.</p></li> </ul> <p>It appears to me that this implementation is a bit too heavy and is not quite as fluid as the stopwatch app. Is there a better, more interactive way to count up time that the app has been running? Maybe there's something already provided by iOS for this purpose? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload