https://github.com/meniny/battery
πAn iOS battery monitor library
https://github.com/meniny/battery
Last synced: about 1 year ago
JSON representation
πAn iOS battery monitor library
- Host: GitHub
- URL: https://github.com/meniny/battery
- Owner: Meniny
- License: mit
- Created: 2017-07-22T02:39:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-22T03:34:12.000Z (almost 9 years ago)
- Last Synced: 2025-04-07T18:49:12.111Z (about 1 year ago)
- Language: Swift
- Size: 22.5 KB
- Stars: 14
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Battery
`Battery` is an easy-to-use class to monitor battery status on iOS.
> Also see [MXBatteryMointor](https://github.com/Meniny/MXBatteryMointor-in-Objective-C) for Objective-C version.
## Installation
#### CocoaPods
```
pod 'Battery'
```
## Usage
```swift
import Battery
```
```swift
Battery.mointor.onBatteryStateChanged = { (state) in
print("State: " + state.stringValue)
}
Battery.mointor.onBatteryLevelChanged = { (level) in
print("Level: " + (level.percentString() ?? "Unknown"))
}
Battery.mointor.start()
```
```swift
let level = Battery.mointor.batteryLevel
let state = Battery.mointor.batteryState
```
```swift
let levelString = Battery.mointor.batteryLevelString
let stateString = Battery.mointor.batteryStateString
```
```swift
Battery.monitor.stop()
```