Reputation: 563
I'm creating an app which works as a boxing timer, counting rounds and playing a sound at the end of each. The problem is that NSTimer stops when the app enters background mode. There are some boxing timers in the app store, so i'm shore there is some way that can be implemented.
Upvotes: 0
Views: 332
Reputation: 1335
You should store current time before going to background ( In your AppDelegate
) :
- (void)applicationWillResignActive:(UIApplication *)application
{
self.startTime = [NSDate date];
.
.
.
// Rest of your code
}
And then do the same when app goes active :
- (void)applicationDidBecomeActive:(UIApplication *)application
{
self.endTime = [NSDate date];
.
.
.
// Rest of your code
}
Then you can subtract them and find out how much the app was in the background and do what you want based on that.
If you want to do something when your app is in the background, you should enable Background Mode
in your app's .plist
file ( or in Capabilities
Section ), which usually is used for VOIP apps or something similar.
Upvotes: 1