Comments (6)
@ajeetpratap Use an observer when sending the app to the background and disable the timer, returning to the foreground subtractthe time difference and initialize the timer again.
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: .UIApplicationWillResignActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: .UIApplicationDidBecomeActive, object: nil)
}
@objc func willResignActive(_ notification: Notification) {
currentBackgroundDate = Date()
timer.invalidate()
}
@objc func didBecomeActive(_ notification: Notification) {
let calender: Calendar = Calendar.current
let components: DateComponents = calender.dateComponents([.year, .month, .day, .hour, .minute, .second], from: currentBackgroundDate!, to: Date())
let seconds = components.second
let secondsUpdate = countDownView.currentSecond - seconds!
countDownView.start(beginingValue: secondsUpdate, interval: 1)
}
from srcountdowntimer.
Having same issue!
from srcountdowntimer.
@app-web-dev I solved it with observers!
from srcountdowntimer.
I am stuck with this same issue.. I want the timer to run even the app goes in background. @resand How you solved it with observer?
from srcountdowntimer.
@resand Thanks for the quick reply:
countDownView.start(beginingValue: secondsUpdate, interval: 1)
will start the timer again and it will also update the UI also.I want to persist the UI and resume it again when I come to foreground.
Any thoughts on that?
from srcountdowntimer.
@ajeetpratap You could check if the library has a function to get the time difference and keep the UI.
He served me as an example.
from srcountdowntimer.
Related Issues (20)
- how to draw gradient trail line? HOT 1
- Getting How much Time is elapsed ? HOT 2
- Circle Not completeing HOT 2
- Fill the circle with a color HOT 1
- Support for fractions of a second HOT 1
- Reset Trail Line HOT 6
- Set Time Label without needing to start the timer HOT 1
- Apple Watch support? HOT 1
- how to detect current text of SRCountdownTimer? HOT 1
- User Flexibility on Timer Progress View Direction. HOT 1
- Seriosuly no upgrade for Swift 4.2? HOT 2
- I need to show timer as rectangular
- Countdown not starting again. HOT 1
- timerDidEnd Function not working HOT 1
- Timer Label not showing HOT 1
- get the interval
- Timer updating after incorrect intervals (not 1 sec).
- Do you have a used code sample?
- SRCcountdownTimer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from srcountdowntimer.