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

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

121 lines
4.4 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.

//
// DeviceModelNameResolver.swift
// suixinkan
//
// utsname
//
import Foundation
import UIKit
///
enum DeviceModelNameResolver {
/// iPhone X
static func marketingName() -> String {
marketingName(forHardwareIdentifier: hardwareIdentifier())
}
///
static func marketingName(forHardwareIdentifier identifier: String) -> String {
if let name = identifierMap[identifier] {
return name
}
return fallbackName(for: identifier)
}
/// 使 SIMULATOR_MODEL_IDENTIFIER
static func hardwareIdentifier() -> String {
#if targetEnvironment(simulator)
if let simulatorIdentifier = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"],
!simulatorIdentifier.isEmpty {
return simulatorIdentifier
}
#endif
var systemInfo = utsname()
uname(&systemInfo)
return withUnsafePointer(to: &systemInfo.machine) {
$0.withMemoryRebound(to: CChar.self, capacity: 1) {
String(cString: $0)
}
}
}
/// 退iPhone / iPad / iPod touch iPhone12,1
private static func fallbackName(for identifier: String) -> String {
if identifier.hasPrefix("iPhone") {
return "iPhone"
}
if identifier.hasPrefix("iPad") {
return "iPad"
}
if identifier.hasPrefix("iPod") {
return "iPod touch"
}
let localized = UIDevice.current.localizedModel.trimmingCharacters(in: .whitespacesAndNewlines)
return localized.isEmpty ? "iPhone" : localized
}
/// Apple
private static let identifierMap: [String: String] = [
// iPhone
"iPhone9,1": "iPhone 7",
"iPhone9,3": "iPhone 7",
"iPhone9,2": "iPhone 7 Plus",
"iPhone9,4": "iPhone 7 Plus",
"iPhone10,1": "iPhone 8",
"iPhone10,4": "iPhone 8",
"iPhone10,2": "iPhone 8 Plus",
"iPhone10,5": "iPhone 8 Plus",
"iPhone10,3": "iPhone X",
"iPhone10,6": "iPhone X",
"iPhone11,2": "iPhone XS",
"iPhone11,4": "iPhone XS Max",
"iPhone11,6": "iPhone XS Max",
"iPhone11,8": "iPhone XR",
"iPhone12,1": "iPhone 11",
"iPhone12,3": "iPhone 11 Pro",
"iPhone12,5": "iPhone 11 Pro Max",
"iPhone12,8": "iPhone SE (2nd generation)",
"iPhone13,1": "iPhone 12 mini",
"iPhone13,2": "iPhone 12",
"iPhone13,3": "iPhone 12 Pro",
"iPhone13,4": "iPhone 12 Pro Max",
"iPhone14,4": "iPhone 13 mini",
"iPhone14,5": "iPhone 13",
"iPhone14,2": "iPhone 13 Pro",
"iPhone14,3": "iPhone 13 Pro Max",
"iPhone14,6": "iPhone SE (3rd generation)",
"iPhone14,7": "iPhone 14",
"iPhone14,8": "iPhone 14 Plus",
"iPhone15,2": "iPhone 14 Pro",
"iPhone15,3": "iPhone 14 Pro Max",
"iPhone15,4": "iPhone 15",
"iPhone15,5": "iPhone 15 Plus",
"iPhone16,1": "iPhone 15 Pro",
"iPhone16,2": "iPhone 15 Pro Max",
"iPhone17,3": "iPhone 16",
"iPhone17,4": "iPhone 16 Plus",
"iPhone17,1": "iPhone 16 Pro",
"iPhone17,2": "iPhone 16 Pro Max",
"iPhone17,5": "iPhone 16e",
// iPad iPad
"iPad13,18": "iPad (10th generation)",
"iPad13,19": "iPad (10th generation)",
"iPad14,1": "iPad mini (6th generation)",
"iPad14,2": "iPad mini (6th generation)",
"iPad13,1": "iPad Air (4th generation)",
"iPad13,2": "iPad Air (4th generation)",
"iPad13,16": "iPad Air (5th generation)",
"iPad13,17": "iPad Air (5th generation)",
"iPad8,1": "iPad Pro 11-inch",
"iPad8,2": "iPad Pro 11-inch",
"iPad8,3": "iPad Pro 11-inch",
"iPad8,4": "iPad Pro 11-inch",
"iPad8,5": "iPad Pro 12.9-inch",
"iPad8,6": "iPad Pro 12.9-inch",
"iPad8,7": "iPad Pro 12.9-inch",
"iPad8,8": "iPad Pro 12.9-inch"
]
}