https://github.com/trymirai/swift-sensors
A Swift package that uses IOKit private APIs and exposes system sensor data including thermal, voltage, current, memory, etc.
https://github.com/trymirai/swift-sensors
battery-monitoring cpu-monitoring diagnostics iokit ios memory-monitoring performance-monitoring sensors swift system-monitoring thermal-monitoring
Last synced: 7 months ago
JSON representation
A Swift package that uses IOKit private APIs and exposes system sensor data including thermal, voltage, current, memory, etc.
- Host: GitHub
- URL: https://github.com/trymirai/swift-sensors
- Owner: trymirai
- License: mit
- Created: 2025-03-19T00:13:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-20T22:46:17.000Z (over 1 year ago)
- Last Synced: 2025-11-18T10:03:52.871Z (7 months ago)
- Topics: battery-monitoring, cpu-monitoring, diagnostics, iokit, ios, memory-monitoring, performance-monitoring, sensors, swift, system-monitoring, thermal-monitoring
- Language: Swift
- Homepage:
- Size: 1.21 MB
- Stars: 22
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftSensors
[](https://swift.org/platforms/)
[](https://swift.org)

A Swift package for accessing real device sensor readings, including thermal, voltage, current, memory, CPU, and disk statistics.
## Features
- Access thermal, voltage, current sensors readings
- Memory usage statistics
- CPU usage statistics
- Disk space information
- System information
- Battery information
- Formatted output for human-readable display
## Installation
### Swift Package Manager
Add the following to your `Package.swift` file:
```swift
dependencies: [
.package(url: "https://github.com/getmirai/swift-sensors.git", from: "0.0.1")
]
```
## Usage
```swift
import SwiftSensors
// Get an instance of the sensor manager
let sensors = SwiftSensors.shared
// Get thermal sensor readings
let thermalReadings = await sensors.getThermalSensorReadings()
for reading in thermalReadings {
print("\(reading.name): \(SensorFormatter.shared.formatTemperature(reading.temperature))")
}
// Get voltage sensor readings
let voltageReadings = await sensors.getVoltageSensorReadings()
for reading in voltageReadings {
print("\(reading.name): \(reading.voltage)V")
}
// Get current sensor readings
let currentReadings = await sensors.getCurrentSensorReadings()
for reading in currentReadings {
print("\(reading.name): \(reading.current)A")
}
// Get memory statistics
let memoryStats = await sensors.getMemoryStats()
print("Memory Usage: \(await sensors.getFormattedMemoryUsage())")
// Get CPU statistics
let cpuStats = await sensors.getCPUStats()
print("CPU Usage: \(await sensors.getFormattedCPUUsage())")
// Get disk statistics
let diskStats = await sensors.getDiskStats()
print("Disk Usage: \(await sensors.getFormattedDiskUsage())")
// Get thermal state
let thermalState = await sensors.getThermalState()
print("Thermal State: \(thermalState.rawValue)")
// Get system uptime
print("System Uptime: \(await sensors.getFormattedUptime())")
```
## Note on Private APIs
This package uses private APIs to access internal device sensors including thermal, voltage, and current readings. While this works well for development and diagnostic purposes, be aware that using private APIs may not be acceptable for App Store submissions.
## License
This project is available under the MIT license. See the [LICENSE](LICENSE) file for more info.