krz/domain-dig

an ios app for DNS & SSL analysis

clone: git clone https://gitbay.org/krz/domain-dig.git

main: DomainDig/AppInfo.swift · raw

 1import Foundation
 2import UIKit
 3
 4/// Runtime app metadata read from the bundle, plus the locally-assembled
 5/// diagnostics used to prefill an issue report. Nothing here touches the network
 6/// or collects any identifier beyond the app version, iOS version, and hardware
 7/// model string.
 8enum AppInfo {
 9    /// CFBundleShortVersionString (marketing version), falling back to the
10    /// compiled-in `AppVersion.current` if the Info.plist key is missing.
11    static var marketingVersion: String {
12        Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? AppVersion.current
13    }
14
15    /// CFBundleVersion (build number).
16    static var buildNumber: String {
17        Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
18    }
19
20    /// "5.0.0 (build 45)"  version alongside build, as the App Info row shows it.
21    static var versionDisplay: String {
22        "\(marketingVersion) (build \(buildNumber))"
23    }
24
25    static let minimumOS = "17.6"
26
27    static var systemVersion: String {
28        UIDevice.current.systemVersion
29    }
30
31    /// Hardware model identifier (e.g. "iPhone15,2")  a model string, not a
32    /// per-device identifier.
33    static var deviceModel: String {
34        var systemInfo = utsname()
35        uname(&systemInfo)
36        let identifier = withUnsafeBytes(of: &systemInfo.machine) { raw -> String in
37            let bytes = raw.prefix { $0 != 0 }
38            return String(decoding: bytes, as: UTF8.self)
39        }
40        return identifier.isEmpty ? "Unknown" : identifier
41    }
42
43    /// Diagnostics prefilled into an issue report. Shown to the user before any
44    /// send  never collected silently.
45    static var diagnosticsReport: String {
46        """
47        DomainDig \(versionDisplay)
48        iOS \(systemVersion)
49        Device \(deviceModel)
50        """
51    }
52}