未连接状态改为「未连接相机」;设备型号映射为可读名称而非 iPhone12,1 等内部代号;边拍边传/拍后传输按账号持久化并在下次进入时恢复。 Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.6 KiB
Swift
47 lines
1.6 KiB
Swift
//
|
||
// DeviceStorageHelper.swift
|
||
// suixinkan
|
||
//
|
||
// 读取本机型号与可用存储,对齐 Android DeviceStorageHelper。
|
||
//
|
||
|
||
import Foundation
|
||
import UIKit
|
||
|
||
/// 设备存储快照,用于有线传图页设备信息面板。
|
||
struct DeviceStorageSnapshot: Equatable {
|
||
let modelName: String
|
||
let availableGbText: String
|
||
}
|
||
|
||
/// 设备存储信息读取工具。
|
||
enum DeviceStorageHelper {
|
||
/// 读取当前设备型号与 Documents 目录可用空间。
|
||
static func readStorageSnapshot() -> DeviceStorageSnapshot {
|
||
let availableBytes = availableDocumentsBytes()
|
||
let availableGb = Double(availableBytes) / 1024.0 / 1024.0 / 1024.0
|
||
return DeviceStorageSnapshot(
|
||
modelName: buildModelName(),
|
||
availableGbText: String(format: "还剩 %.1fGB 可用", availableGb)
|
||
)
|
||
}
|
||
|
||
private static func buildModelName() -> String {
|
||
DeviceModelNameResolver.marketingName()
|
||
}
|
||
|
||
private static func availableDocumentsBytes() -> Int64 {
|
||
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
|
||
guard let documentsURL else { return 0 }
|
||
let values = try? documentsURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey])
|
||
if let capacity = values?.volumeAvailableCapacityForImportantUsage {
|
||
return Int64(capacity)
|
||
}
|
||
if let attributes = try? FileManager.default.attributesOfFileSystem(forPath: documentsURL.path),
|
||
let freeSize = attributes[.systemFreeSize] as? NSNumber {
|
||
return freeSize.int64Value
|
||
}
|
||
return 0
|
||
}
|
||
}
|