{"id":19685893,"url":"https://github.com/rxswiftcommunity/rxbatterymanager","last_synced_at":"2025-06-13T14:11:10.082Z","repository":{"id":54737789,"uuid":"266704162","full_name":"RxSwiftCommunity/RxBatteryManager","owner":"RxSwiftCommunity","description":"A Reactive BatteryManager in Swift for iOS","archived":false,"fork":false,"pushed_at":"2021-02-01T17:18:40.000Z","size":51,"stargazers_count":24,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T10:32:03.638Z","etag":null,"topics":["battery-information","battery-level","battery-monitor","battery-status","rx","rxcocoa","rxswift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RxSwiftCommunity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-25T06:44:01.000Z","updated_at":"2025-04-29T09:12:18.000Z","dependencies_parsed_at":"2022-08-14T01:20:15.535Z","dependency_job_id":null,"html_url":"https://github.com/RxSwiftCommunity/RxBatteryManager","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/RxSwiftCommunity/RxBatteryManager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxBatteryManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxBatteryManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxBatteryManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxBatteryManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RxSwiftCommunity","download_url":"https://codeload.github.com/RxSwiftCommunity/RxBatteryManager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxBatteryManager/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259659667,"owners_count":22891672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["battery-information","battery-level","battery-monitor","battery-status","rx","rxcocoa","rxswift"],"created_at":"2024-11-11T18:24:36.318Z","updated_at":"2025-06-13T14:11:10.057Z","avatar_url":"https://github.com/RxSwiftCommunity.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Reactive BatteryManager in Swift\n\n[![Build Status](https://travis-ci.com/mustafagunes/RxBatteryManager.svg?branch=master)](https://github.com/mustafagunes/RxBatteryManager)\n[![Swift](https://img.shields.io/badge/swift-5.1-orange.svg)](https://github.com/mustafagunes/RxBatteryManager)\n[![RxSwift](https://img.shields.io/badge/RxSwift-5.1.1-red.svg)](https://github.com/ReactiveX/RxSwift)\n[![SPM Compatible](https://img.shields.io/badge/SPM-1.0.3-brightgreen.svg)](https://swift.org/package-manager)\n[![CocoaPods Compatible](https://img.shields.io/badge/Cocoapod-1.0.3-brightgreen.svg)](https://cocoapods.org)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-not%20supported-lightgrey.svg)](https://github.com/Carthage/Carthage)\n[![Platform](https://img.shields.io/badge/Platform-%20iOS-lightgrey.svg)](https://github.com/mustafagunes/RxBatteryManager)\n[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/mustafagunes/RxBatteryManager/blob/master/LICENSE)\n\n## Motivation\nI needed a battery manager when developing my apps with Rx. And I started to write the manager. With the battery manager, you can stream data from your battery in a reactive manner. For example, by subscribing to the critical battery status of your battery, you can improve the user experience and reduce battery usage by changing the dark/light modes of your application. I wanted to share this library I developed with the community. My biggest motivation was that the community was very helpful and friendly. I hope useful.\n\n## 🛠 Requirements\n* iOS 9.0+\n* Xcode 11+\n* Swift 5.1+\n* RxSwift 5.1.1+\n\n## ⚙️ Installation\n\n### Swift Package Manager (requires Xcode 11)\nAdd package into Project settings -\u003e Swift Packages\n\n### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)\nAdd RxBatteryManager dependency to your Podfile\n```\n# Podfile\nuse_frameworks!\n\n# replace YOUR_TARGET_NAME with yours\ntarget 'YOUR_TARGET_NAME' do\n    pod 'RxBatteryManager',    '~\u003e 1.0'\nend\n```\nand run \n```\n$ pod install\n```\n\n## 👨‍💻 Usage\n```swift\nimport RxBatteryManager\n```\n\n#### Singleton RxBatteryManager\n```swift\nlet battery = Battery.monitor\n```\n\n#### Init Library in AppDelegate\n```swift\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n        \n    // Monitoring Battery\n    Battery.monitor.start()\n    \n    return true\n}\n```\n\n#### *level* - float returns\n```swift\nbattery.level\n    .observeOn(MainScheduler.instance)\n    .subscribe(onNext: { [weak self] level in\n        guard let self = self else { return }\n        print(level)\n    }).disposed(by: disposeBag)\n```\n\n#### *state* - UIDevice.Enum returns in BatteryState type\n```swift\nbattery.state\n    .observeOn(MainScheduler.instance)\n    .subscribe(onNext: { [weak self] state in\n        guard let self = self else { return }\n        switch state {\n        case .unknown:\n            print(\"unknown\")\n        case .unplugged:\n            print(\"unplugged\")\n        case .charging:\n            print(\"charging\")\n        case .full:\n            print(\"full\")\n        @unknown default:\n            fatalError()\n        }\n    }).disposed(by: disposeBag)\n```\n\n#### *isLowPowerMode* - bool returns\n```swift\nbattery.isLowPowerMode\n    .observeOn(MainScheduler.instance)\n    .subscribe(onNext: { [weak self] isLowPowerMode in\n        guard let self = self else { return }\n        print(isLowPowerMode)\n    }).disposed(by: disposeBag)\n```\n\n#### *isLowLevel* - bool returns\n```swift\nbattery.isLowLevel\n    .observeOn(MainScheduler.instance)\n    .distinctUntilChanged()\n    .subscribe(onNext: { [weak self] isLowLevel in\n        guard let self = self else { return }\n        self.isLowBatteryLabel.text = \"\\(isLowLevel)\"\n    }).disposed(by: disposeBag)\n```\n\n#### *isCriticalLevel* - bool returns\n```swift\nbattery.isCriticalLevel\n    .observeOn(MainScheduler.instance)\n    .distinctUntilChanged()\n    .subscribe(onNext: { [weak self] isCriticalLevel in\n        guard let self = self else { return }\n        self.isCriticalBatteryLabel.text = \"\\(isCriticalLevel)\"\n    }).disposed(by: disposeBag)\n```\n\n**Note: I recommend you subscribe to Main Thread**\n\n## 👮‍♂️License\n\nRxBatteryManager is available under the [MIT](https://github.com/mustafagunes/RxBatteryManager/blob/master/LICENSE) license. See the LICENSE file for more info.\nCopyright (c) RxSwiftCommunity\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxswiftcommunity%2Frxbatterymanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frxswiftcommunity%2Frxbatterymanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxswiftcommunity%2Frxbatterymanager/lists"}