Files
suixinkan_ios_new/suixinkan/Features/TravelAlbum/Services/DeviceStorageHelper.swift
汉秋 c71b45bdfd 对齐有线传图页 Android UI,并改用相对路径持久化本地照片。
还原顶栏、浮动卡片、时间侧栏与底部交互;照片路径改为 CameraDownloads 相对路径并兼容旧数据;格式 Chip 固定 JPG 且不可点击。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 11:16:28 +08:00

59 lines
2.1 KiB
Swift
Raw 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 {
var systemInfo = utsname()
uname(&systemInfo)
let machine = withUnsafePointer(to: &systemInfo.machine) {
$0.withMemoryRebound(to: CChar.self, capacity: 1) {
String(cString: $0)
}
}
let marketingName = UIDevice.current.name.trimmingCharacters(in: .whitespacesAndNewlines)
if !marketingName.isEmpty, marketingName != "iPhone", !marketingName.hasPrefix("iPad") {
return marketingName
}
if !machine.isEmpty { return machine }
return UIDevice.current.model
}
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
}
}