1.开始录制、结束录制增加

2. 增加电量检测、内存检查,是否低于 10%
This commit is contained in:
2026-06-04 18:25:58 +08:00
parent 124b4c1882
commit f49d208042
9 changed files with 267 additions and 0 deletions

View File

@@ -17,6 +17,8 @@ final class PlatformInfoPlugin: NSObject, FlutterPlugin {
result(packageInfoMap())
case "deviceInfo":
result(deviceInfoMap())
case "deviceHealth":
result(deviceHealthMap())
default:
result(FlutterMethodNotImplemented)
}
@@ -32,6 +34,30 @@ final class PlatformInfoPlugin: NSObject, FlutterPlugin {
]
}
private func deviceHealthMap() -> [String: Any?] {
let device = UIDevice.current
device.isBatteryMonitoringEnabled = true
var batteryLevelPercent: Int?
let batteryLevel = device.batteryLevel
if batteryLevel >= 0 {
batteryLevelPercent = Int((batteryLevel * 100).rounded())
}
var storageAvailablePercent = 100.0
if let attrs = try? FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory()),
let free = attrs[.systemFreeSize] as? NSNumber,
let total = attrs[.systemSize] as? NSNumber,
total.doubleValue > 0 {
storageAvailablePercent = free.doubleValue / total.doubleValue * 100.0
}
return [
"batteryLevelPercent": batteryLevelPercent,
"storageAvailablePercent": storageAvailablePercent,
]
}
private func deviceInfoMap() -> [String: Any] {
let device = UIDevice.current
return [