I have an application that has a NSTimer running as long as the button is being pressed. However, if the user exits out of the app (Multi-tasks) the timer continues to go. How can I invalidate it so that the time stops and is set to nil when the app is being exited. Can I disable multi-tasking? Thanks. P.S If it involves using the AppDelegate how do I get that NSTimer to be referenced in the AppDelegate, because it is created in the ViewController.h
I have tired using:
#import "Some AppNameViewController.h"
Anyway, thanks in advance!
You can disable multi tasking by setting
UIApplicationExitsOnSuspendto YES in your plist.The more elegant solution is to listen for the
UIApplicationWillResignActiveNotificationor theUIApplicationDidEnterBackgroundNotificationin the class with the timer. When either of those notification are postedinvalidateandnilyour timer.