iOS/Cocoa Event Timing with MPStopwatch
Marshmallow Stopwatch on Github
This is the latest addition to the Marshmallows library. It’s a simple class I designed for getting a deeper analysis of user interaction timings in an app. The results are then reported to the app’s analytics. It supports “marks” (like the “lap” button on stopwatches) as well as pausing.
Example Usage:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
@implementation MyAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { myStopwatch = [MPStopwatch alloc] init]; // starts the timer [myStopwatch pause]; totalTimePaused = 0.0; totalTimePlayed = 0.0; } - (void)playDidBegin { totalTimePaused += [myStopwatch resume]; // Returns duration of last pause period } - (void)playDidEnd { totalTimePlayed += [myStopwatch pause]; // Returns duration of last running period } - (void)applicationWillTerminate:(UIApplication *)application { [MyAnalytics reportEvent:@"Session Play Time" value:totalTimePlayed]; [MyAnalytics reportEvent:@"Session Pause Time" value:totalTimePaused]; } @end |
