Files
suixinkan_ios_new/suixinkan/Features/TravelAlbum/Services/DeviceStorageHelper.swift
汉秋 ceac8ba67e 优化有线传图页设备展示,并缓存传输模式选项。
未连接状态改为「未连接相机」;设备型号映射为可读名称而非 iPhone12,1 等内部代号;边拍边传/拍后传输按账号持久化并在下次进入时恢复。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 14:07:34 +08:00

47 lines
1.6 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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
}
}