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

Countdown being reseted due long time in background #5

Open
rafaismyname opened this issue Mar 18, 2014 · 5 comments
Open

Countdown being reseted due long time in background #5

rafaismyname opened this issue Mar 18, 2014 · 5 comments

Comments

@rafaismyname
Copy link

Hello there! How being doing?
Thanks for this awesome pod! :)

I'm currently having issues while running a countdown at background. If somehow the counter is more then 20 minutes or so, it resets when i get back to the app... How can i avoid this?

Best!
Rafa

@mineschan
Copy link
Owner

Hi Rafa, I'm glad you like it.

I've tried your situation, so far it's okay for me. What iOS version u using?

@rafaismyname
Copy link
Author

Yep, its super cool, thanks for this pod!

I'm under 7.0....
I don't know if thats the issue, but i think its a memory warning issue... :(
Once it worked for half an hour in background, but not for an full hour... it also depends on the phone usage...

I think ill store when i started the timer, and when the app comes active again, it re-starts the timmer again...

What you think?

@mineschan
Copy link
Owner

Even in the example those timers only use like 25mb of memory. I am not sure if it's about the memory.

Is it only the timer reset or the others thing like views and view controllers?

@basememara
Copy link

I'm seeing strange things too when the timer goes in the background for 20+ mins. To get around this, I had to do this:

    override func viewDidLoad() {
        countdownTimer = MZTimerLabel(label: myLabel, andTimerType: MZTimerLabelTypeTimer)

        // When app becomes active, re-run to refresh timer
        NSNotificationCenter.defaultCenter().addObserver(self,
            selector: "updateCountDownTimer",
            name: UIApplicationWillEnterForegroundNotification,
            object: nil)
    }

    override func viewWillAppear(animated: Bool) {
        timerDate = //some date
        countdownTimer.setCountDownToDate(timerDate)
        countdownTimer.start()
    }

    func updateCountDownTimer() {
        // Countdown looses its place after app leaves foreground for 20+ mins
        if timerDate > NSDate() {
            countdownTimer.reset()
            countdownTimer.setCountDownToDate(timerDate)
            countdownTimer.start()
        }
    }

@mineschan mineschan reopened this Aug 7, 2015
@mineschan
Copy link
Owner

hey @basememara thanks first. But is that anyway i can bundle your workaround into MZTimerLabel that not requires any further custom implementation from user? otherwise i will try to put this into readme ;)

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

3 participants