https://github.com/jonnybeegod/restorablecountdown
Native Timer-based Countdown written in Swift
https://github.com/jonnybeegod/restorablecountdown
countdown countdown-timer countdowntimer ios swift swift-package-manager timer
Last synced: about 1 year ago
JSON representation
Native Timer-based Countdown written in Swift
- Host: GitHub
- URL: https://github.com/jonnybeegod/restorablecountdown
- Owner: JonnyBeeGod
- License: mit
- Created: 2019-12-21T09:51:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-31T04:47:48.000Z (over 6 years ago)
- Last Synced: 2025-02-09T00:41:36.095Z (about 1 year ago)
- Topics: countdown, countdown-timer, countdowntimer, ios, swift, swift-package-manager, timer
- Language: Swift
- Homepage:
- Size: 84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Restorable Countdown

[](https://codecov.io/gh/JonnyBeeGod/RestorableCountdown)
Restorable Countdown is a convenient framework for managing long running countdowns written in Swift for Cocoa.
# What does it do?
Restorable Countdown allows for managing very long running timers and countdowns. It is a wrapper around Swift Foundations `Timer` class and gracefully saves and restores its state when the application goes into background by hooking in the `UApplicationDelegate` / `NSApplicationDelegate` lifecycle methods. Restorable Countdown is compatible with all four relevant platforms iOS / iPadOS, macOS, tvOS and watchOS. It also supports sending local notifications on completion.
# How to install?
Restorable Countdown is compatible with Swift Package Manager. To install, simply add this repository URL to your swift packages as package dependency in Xcode.
Alternatively, add this line to your `Package.swift` file:
```
dependencies: [
.package(url: "https://github.com/JonnyBeeGod/RestorableCountdown", from: "0.1.0")
]
```
And don't forget to add the dependency to your target(s).
# How to use?
1. Initialize a `CountdownConfiguration` and configure it to your needs. As a start you can also use the predefined values and go from here.
2. Create a `Countdown` object and feed it the configuration from step 1 and a `CountdownDelegate`
3. Call `startCountdown()`
## Notifications
Inject a `UNUserNotificationCenter` as well as a `UNUserNotificationContent` object on initialization if you want to schedule a local notification when the countdown has finished. Make sure that you have asked for user permissions before, see [here](https://developer.apple.com/documentation/usernotifications/asking_permission_to_use_notifications).
# Caveats
- [ ] Currently no background execution supported meaning that the countdown will stop firing and executing code as soon as the app is in the background. When the app goes into foreground again the timer resumes and / or finishes.
The reason for this is that the options we get from Apple for executing code in the background are very limited and have gotten even more restrictive in the past. I was previously using means to extend background execution time as described [here](https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/extending_your_app_s_background_execution_time), but discovered that this is not a solution for very long running timers over a couple of minutes. Modes for background execution might be added later but will probably only be possible with some limitations as or the reasons described above.