Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call delegate method while app in background #24

Open
Morpheus2002 opened this issue Dec 2, 2014 · 6 comments
Open

Call delegate method while app in background #24

Morpheus2002 opened this issue Dec 2, 2014 · 6 comments

Comments

@Morpheus2002
Copy link

I'm starting a countdown timer with a click on button in my app and set time to 10 seconds. After the countdown is finished, I start another countdown timer with 30 seconds. I use the delegate method -(void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime to start second timer.
However, if I close the app immediatly after the first countdown timer started, the delegate method is never called and the second timer never starts. Only after I open the app.

Any idea how to start new timer while app is in background?

@Morpheus2002 Morpheus2002 changed the title Call delega method while app in background Call delegate method while app in background Dec 2, 2014
@mineschan
Copy link
Owner

Hi,

Currently MZTimerLabel is not aim for working in the the background. Sorry about that.
And I think if you terminate the app, Apple would not suggest you to keep counting using the timer way.

I would suggest you to save the counting timer information before you terminate the app via AppDelegate. And when you launch the app again, loop through those saved timers and determine if the timer should be ended and perform following actions.

Cheers,
MineS

@Morpheus2002
Copy link
Author

I'm not terminating the app. Just closing it by clicking the home button. So it actually should work in background.

I also found out something wired. The timer and delegate calls working fine in simulator, but not working in my iPhone 6. The delegate method is not called if the app is in background.

Any ideas?

@mineschan
Copy link
Owner

So you mean when you using simulator, the delegate method called even in background?

@mineschan
Copy link
Owner

How long it takes you after minimize the app and the delegate should call?

@Morpheus2002
Copy link
Author

I created a property for MZTimerLabel in my Appdelegate. This way it works in background. Already tested in my other project.

I got one timer with two settings: 10 seconds and 30 seconds.
Here are the steps I'm doing.

  1. I start the timer with 10 seconds
    [appDelegate.mzTimerLabel setCountDownTime:10];
    [appDelegate.mzTimerLabel start];
  2. After it's done I call the delegate, and check what time was set previously.
  3. I set up the time to 30 seconds and start the timer again.
  4. After this timer is done, I call delegate again and start 10 seconds time. This way it runs for 8 minutes.

Here is my delegate method:

- (void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime
{
    if (countTime == 10) {

        [appDelegate.mzTimerLabel setCountDownTime:30];
        [appDelegate.mzTimerLabel start];

        }else{

         [appDelegate.mzTimerLabel setCountDownTime:10];
         [appDelegate.mzTimerLabel start];

        }
}

@mineschan
Copy link
Owner

let me investigate a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants