0

For my stopWatch project, i want to run the timer, when application goes to background (like "stopwatch" inside iPhone clock). I have tried 'beginBackgrounTaskWithExpirationHandler', but it will only execute the task up to 10 minutes. How can i do this without this limit. can any one help me how to solve this ....

Thanks for your quick reply.. Here is my code:

ViewController.m

- (void)countDown{
    count = count - 1;

    //until 30 minutes i need to play an animation here... 

        if(count == 0)
        {
           //close timer...
        [myTimer invalidate];
        myTimer = nil;

           //update counter again
             [self updateCounter];
        }
}

//update counter function...

- (void)updateCounter{

    //setting count value
    count = 1800;

    //count-down fun
    myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(countDown) userInfo:nil repeats:YES];

}

This is what i am looking to execute even in the background.... help me please..

shebi
  • 707
  • 2
  • 14
  • 23

2 Answers2

0
  1. You can't (extend the background time of your app)
  2. Use a local notification instead.
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
0

Actually, if you only need the time, simply adjust your clock when you application becomes active again.

If you need to be active at a certain time, use scheduleAlarmForDate:, see Apple documentation.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
Matthias
  • 8,018
  • 2
  • 27
  • 53
  • `scheduleAlarmForDate` is not a framework method. You should at least provide a link to the source code. – Nikolai Ruhe Apr 05 '12 at 07:34
  • Thanks for your quick reply.. ViewController.m: - (void)countDown{ count = count - 1; //until 30 minutes i need to play an animation here... } myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(countDown) userInfo:nil repeats:YES]; – shebi Apr 05 '12 at 07:52
  • @shebi: You will have the same problem. Use local notifications, or even better, use it *only* for the action at end of the countdown, and adjust you counter when the application becomes active (`applicationDidBecomeActive:`). – Matthias Apr 05 '12 at 09:10