All Projects → RxSwiftCommunity → RxBatteryManager

RxSwiftCommunity / RxBatteryManager

Licence: MIT license
A Reactive BatteryManager in Swift for iOS

Programming Languages

swift
15916 projects
shell
77523 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to RxBatteryManager

PureBatteryAnalytics
This is a repository for Pure Battery Analytics. Both the System Tray Add-on & Main Application.
Stars: ✭ 46 (+119.05%)
Mutual labels:  battery-level, battery-monitor, battery-status
powir
Powir is a Windows 10 based tool to monitor and analyze your system's power and battery usage.
Stars: ✭ 119 (+466.67%)
Mutual labels:  battery-monitor, battery-information, battery-status
Rxmarvel
Playing around marvel public API with RxSwift, Argo, Alamofire
Stars: ✭ 86 (+309.52%)
Mutual labels:  rxswift, rx
Moyamapper
快速解析模型工具,支持RxSwift。同时支持缓存功能 【相关手册 https://MoyaMapper.github.io 】
Stars: ✭ 115 (+447.62%)
Mutual labels:  rxswift, rx
bat
Battery management utility for Linux laptops.
Stars: ✭ 107 (+409.52%)
Mutual labels:  battery-level, battery-monitor
GITGET
GitHub의 Contributions를 iOS의 Widget으로 보여주는 App
Stars: ✭ 101 (+380.95%)
Mutual labels:  rxswift, rxcocoa
MovieInfoMVVMiOS
Movie Info app using TMDb API built with MVVM
Stars: ✭ 38 (+80.95%)
Mutual labels:  rxswift, rxcocoa
Combinerxswiftperformance
A test suite comparing the performance of Combine and RxSwift
Stars: ✭ 154 (+633.33%)
Mutual labels:  rxswift, rx
StackBarButtonItem
🔲 StackBarButtonItem can use BarButtonItem like StackView
Stars: ✭ 55 (+161.9%)
Mutual labels:  rxswift, rxcocoa
CLE-Architecture-Tools
A library for making view controller presentation and dismissal more functional.
Stars: ✭ 32 (+52.38%)
Mutual labels:  rxswift, rxcocoa
RxCocoa-Texture
RxCocoa Extension Library for Texture.
Stars: ✭ 98 (+366.67%)
Mutual labels:  rxswift, rxcocoa
Cathay
an iOS project for demonstration of Reactive Programming
Stars: ✭ 21 (+0%)
Mutual labels:  rxswift, rxcocoa
Mp3ID3Tagger
🎶🎵A macOS application to edit the ID3 tag of your mp3 files. Developed with RxSwift and RxCocoa. 🎸🎼
Stars: ✭ 17 (-19.05%)
Mutual labels:  rxswift, rxcocoa
DailyNews
Daily News is a news app with good looking user interface ! Apps architecture is MVVM and used RxSwift for binding.
Stars: ✭ 31 (+47.62%)
Mutual labels:  rxswift, rxcocoa
RxEureka
This library is a small RxSwift wrapper around Eureka
Stars: ✭ 37 (+76.19%)
Mutual labels:  rxswift, rx
Bark
Bark is an iOS App which allows you to push customed notifications to your iPhone
Stars: ✭ 2,371 (+11190.48%)
Mutual labels:  rxswift, rxcocoa
minimalist
Observable Property and Signal for building data-driven UI without Rx
Stars: ✭ 88 (+319.05%)
Mutual labels:  rxswift, rx
awesome-demo-app
100% programmatically written in Swift. Clearly demonstrating the RxSwift, RxCocoa, RxRealm & SnapKit.
Stars: ✭ 16 (-23.81%)
Mutual labels:  rxswift, rxcocoa
RxStudy
RxSwift/RxCocoa框架,MVVM模式编写wanandroid客户端
Stars: ✭ 122 (+480.95%)
Mutual labels:  rxswift, rxcocoa
WhatFilm
Simple iOS app using TMDb API and RxSwift
Stars: ✭ 35 (+66.67%)
Mutual labels:  rxswift

A Reactive BatteryManager in Swift

Build Status Swift RxSwift SPM Compatible CocoaPods Compatible Carthage Compatible Platform License

Motivation

I 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.

🛠 Requirements

  • iOS 9.0+
  • Xcode 11+
  • Swift 5.1+
  • RxSwift 5.1.1+

⚙️ Installation

Swift Package Manager (requires Xcode 11)

Add package into Project settings -> Swift Packages

CocoaPods

Add RxBatteryManager dependency to your Podfile

# Podfile
use_frameworks!

# replace YOUR_TARGET_NAME with yours
target 'YOUR_TARGET_NAME' do
    pod 'RxBatteryManager',    '~> 1.0'
end

and run

$ pod install

👨‍💻 Usage

import RxBatteryManager

Singleton RxBatteryManager

let battery = Battery.monitor

Init Library in AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
    // Monitoring Battery
    Battery.monitor.start()
    
    return true
}

level - float returns

battery.level
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] level in
        guard let self = self else { return }
        print(level)
    }).disposed(by: disposeBag)

state - UIDevice.Enum returns in BatteryState type

battery.state
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] state in
        guard let self = self else { return }
        switch state {
        case .unknown:
            print("unknown")
        case .unplugged:
            print("unplugged")
        case .charging:
            print("charging")
        case .full:
            print("full")
        @unknown default:
            fatalError()
        }
    }).disposed(by: disposeBag)

isLowPowerMode - bool returns

battery.isLowPowerMode
    .observeOn(MainScheduler.instance)
    .subscribe(onNext: { [weak self] isLowPowerMode in
        guard let self = self else { return }
        print(isLowPowerMode)
    }).disposed(by: disposeBag)

isLowLevel - bool returns

battery.isLowLevel
    .observeOn(MainScheduler.instance)
    .distinctUntilChanged()
    .subscribe(onNext: { [weak self] isLowLevel in
        guard let self = self else { return }
        self.isLowBatteryLabel.text = "\(isLowLevel)"
    }).disposed(by: disposeBag)

isCriticalLevel - bool returns

battery.isCriticalLevel
    .observeOn(MainScheduler.instance)
    .distinctUntilChanged()
    .subscribe(onNext: { [weak self] isCriticalLevel in
        guard let self = self else { return }
        self.isCriticalBatteryLabel.text = "\(isCriticalLevel)"
    }).disposed(by: disposeBag)

Note: I recommend you subscribe to Main Thread

👮‍♂️License

RxBatteryManager is available under the MIT license. See the LICENSE file for more info. Copyright (c) RxSwiftCommunity

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].