I am trying to get my app to determine, upon launch, if the timer was running when the app quit (or went inactive). Here is my code:
View.m (defaults is [NSUserDefaults standardUserDefaults] and timerIsRunning is declared as "bool timerIsRunning" in the .h)
Code:
- (IBAction)clockIn:(id)sender {
if (timerIsRunning == NO) {
mainInt = [defaults floatForKey:@"wageIsPause"];
randomMain = [NSTimer scheduledTimerWithTimeInterval:(0.1/1.0) target:self selector:@selector(randomMainVoid) userInfo:nil repeats:YES];
timerIsRunning = YES;
[defaults setBool:timerIsRunning forKey:@"timerRun"];
[defaults synchronize];
In my delegate.m file
Code:
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSUserDefaults *defaultsOpen = [NSUserDefaults standardUserDefaults];
[defaultsOpen synchronize];
bool timerIsRunning = [defaultsOpen boolForKey:@"timerRun"];
if (timerIsRunning == NO) {
NSLog(@"Timer is not running.");
}
else {
NSLog(@"Timer is running.");
}
}
The problem is that when I open my app and the timer is running, it logs "Timer is not running." It also logs "Timer is not running." when the timer isn't running (which was to be expected.) I am getting no errors or warnings.
What am I missing here?