let tiff = properties[kCGImagePropertyTIFFDictionary] as? [CFString: Any] let exif = properties[kCGImagePropertyExifDictionary] as? [CFString: Any] // Get the Apple-specific metadata dictionary
// 使用官方支持的字段 let originalLens = exif?[kCGImagePropertyExifLensModel] as?String
let make = (tiff?[kCGImagePropertyTIFFMake] as?String??"").trimmingCharacters( in: .whitespaces) let model = (tiff?[kCGImagePropertyTIFFModel] as?String??"").trimmingCharacters( in: .whitespaces)
let iso = exif?[kCGImagePropertyExifISOSpeedRatings] as? [Int] ?? [] let focalLength = exif?[kCGImagePropertyExifFocalLength] as?Double let aperture = exif?[kCGImagePropertyExifFNumber] as?Double let shutterSpeedValue = exif?[kCGImagePropertyExifExposureTime] as?Double let exposureBias = exif?[kCGImagePropertyExifExposureBiasValue] as?Double
// Define lens replacement map let lensReplacementMap: [String: String] = [ "iPhone 15 Pro Max back triple camera 6.765mm f/1.78": "Main Camera — 24 mm ƒ1.78", // Add more replacements here: // "Original Lens Model String": "Desired Replacement String", "iPhone 15 Pro Max back triple camera 9.03mm f/2.8": "Telephoto Camera — 77 mm ƒ2.8", "iPhone 15 Pro Max back triple camera 2.22mm f/2.2": "Ultra Wide Camera — 13 mm ƒ2.2", ]
// Apply replacement if found, otherwise use the original lens string let lens = originalLens.flatMap { lensReplacementMap[$0] } ?? originalLens
// Check for HDR let isHDR: Bool= checkImageIsHDR(for: fileURL)
// 构造输出格式 var parts: [String] = [] if!make.isEmpty ||!model.isEmpty { parts.append("\(make)\(model)") } iflet isoValue = iso.first { parts.append("ISO \(isoValue)") } iflet fl = focalLength { parts.append("\(Int(round(fl)))mm") } iflet ap = aperture { parts.append("ƒ\(String(format: "%.1f", ap))") } iflet ss = shutterSpeedValue { if ss >=1.0 { parts.append("\(Int(ss)) s") } else { let denominator =Int(round(1.0/ ss)) parts.append("1/\(denominator) s") } } iflet ev = exposureBias { ifabs(ev) <0.001 { parts.append("") } else { parts.append("\(String(format: "%+.1f", ev))ev") } } iflet lens = lens { parts.append("\(lens)") } // Append HDR tag if the image is HDR if isHDR { parts.append("HDR") }
{ "iPhone 15 Pro Max back triple camera 6.765mm f/1.78": "Main Camera — 24 mm ƒ1.78", "iPhone 15 Pro Max back triple camera 9.03mm f/2.8": "Telephoto Camera — 77 mm ƒ2.8", "iPhone 15 Pro Max back triple camera 2.22mm f/2.2": "Ultra Wide Camera — 13 mm ƒ2.2" }