Countdown being reseted due long time in background #5

Open
rafaelamorim opened this Issue Mar 18, 2014 · 5 comments

Comments

Projects
None yet
3 participants
@rafaelamorim

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

This comment has been minimized.

Show comment
Hide comment
@mineschan

mineschan Mar 20, 2014

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?

Owner

mineschan commented Mar 20, 2014

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?

@rafaelamorim

This comment has been minimized.

Show comment
Hide comment
@rafaelamorim

rafaelamorim Mar 23, 2014

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?

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

This comment has been minimized.

Show comment
Hide comment
@mineschan

mineschan Mar 24, 2014

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?

Owner

mineschan commented Mar 24, 2014

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?

@mineschan mineschan closed this Sep 3, 2014

@basememara

This comment has been minimized.

Show comment
Hide comment
@basememara

basememara Jun 22, 2015

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()
        }
    }

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

This comment has been minimized.

Show comment
Hide comment
@mineschan

mineschan Aug 7, 2015

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 ;)

Owner

mineschan commented Aug 7, 2015

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