From 7ff7c1e1622e15178a33de5c5a9874c7126c52b1 Mon Sep 17 00:00:00 2001 From: Brandon Stillitano Date: Sun, 7 Apr 2024 22:56:01 +1000 Subject: [PATCH] Add AIP and hardware year to main menu --- .../Extensions/Bundle+Extensions.swift | 43 +++++++++++++++++-- .../Extensions/UIDevice+Extensions.swift | 12 +++--- .../User Interface/Menu/MenuViewModel.swift | 12 +++++- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/Sources/Scyther/Extensions/Bundle+Extensions.swift b/Sources/Scyther/Extensions/Bundle+Extensions.swift index 3378d3b6..a8706c90 100644 --- a/Sources/Scyther/Extensions/Bundle+Extensions.swift +++ b/Sources/Scyther/Extensions/Bundle+Extensions.swift @@ -25,13 +25,48 @@ extension Bundle { } return infoAttributes[.modificationDate] as? Date ?? Date() } + + + /// Returns the "App Identifier Prefix" for the application. This is also commonly referred to as the "Seed ID" or the "Team ID". + /// https://stackoverflow.com/questions/11726672/access-app-identifier-prefix-programmatically + public var seedId: String? { + let queryLoad: [String: AnyObject] = [ + kSecClass as String: kSecClassGenericPassword, + kSecAttrAccount as String: "bundleSeedID" as AnyObject, + kSecAttrService as String: "" as AnyObject, + kSecReturnAttributes as String: kCFBooleanTrue + ] + + var result: AnyObject? + var status = withUnsafeMutablePointer(to: &result) { + SecItemCopyMatching(queryLoad as CFDictionary, UnsafeMutablePointer($0)) + } + + if status == errSecItemNotFound { + status = withUnsafeMutablePointer(to: &result) { + SecItemAdd(queryLoad as CFDictionary, UnsafeMutablePointer($0)) + } + } + + if status == noErr { + if let resultDict = result as? [String: Any], let accessGroup = resultDict[kSecAttrAccessGroup as String] as? String { + let components = accessGroup.components(separatedBy: ".") + return components.first + } else { + return nil + } + } else { + print("Error getting bundleSeedID to Keychain") + return nil + } + } } /// Cocoapods Specific Extensions #if !SWIFT_PACKAGE -extension Bundle { - static var module: Bundle { - Bundle(identifier: "org.cocoapods.Scyther")! + extension Bundle { + static var module: Bundle { + Bundle(identifier: "org.cocoapods.Scyther")! + } } -} #endif diff --git a/Sources/Scyther/Extensions/UIDevice+Extensions.swift b/Sources/Scyther/Extensions/UIDevice+Extensions.swift index fd92b427..a529eeca 100644 --- a/Sources/Scyther/Extensions/UIDevice+Extensions.swift +++ b/Sources/Scyther/Extensions/UIDevice+Extensions.swift @@ -14,7 +14,7 @@ public extension UIDevice { /// Get System Info var systemInfo = utsname() uname(&systemInfo) - + /// Determine Device Identifier let machineMirror = Mirror(reflecting: systemInfo.machine) let identifier = machineMirror.children.reduce("") { identifier, element in @@ -23,20 +23,20 @@ public extension UIDevice { } return identifier + String(UnicodeScalar(UInt8(value))) } - + return identifier } - + /// Determines the type of device that this code is running on. Returns one of the following: `phone` or `tablet` var deviceType: String { //Check Type if UIDevice.current.userInterfaceIdiom == .pad { return "tablet" } - + return "phone" } - + /// Determines the generation of the running device. var generation: Float { /// Setup Data @@ -45,7 +45,7 @@ public extension UIDevice { value = value.replacingOccurences(of: ["iphone", "ipad", "ipod", "watch"], with: "") value = value.replacingOccurences(of: ["x86_64", "i386"], with: "99.9") value = value.replacingOccurrences(of: ",", with: ".") - + /// Add 2007 to the value as that was the year of release for the first generation of iOS return (Float(value) ?? 0) + 2007 } diff --git a/Sources/Scyther/User Interface/Menu/MenuViewModel.swift b/Sources/Scyther/User Interface/Menu/MenuViewModel.swift index f29ccad0..29d56fe5 100644 --- a/Sources/Scyther/User Interface/Menu/MenuViewModel.swift +++ b/Sources/Scyther/User Interface/Menu/MenuViewModel.swift @@ -115,16 +115,26 @@ internal class MenuViewModel { deviceSection.rows.append(valueRow(name: "Hardware", value: UIDevice.current.modelName, icon: nil)) + deviceSection.rows.append(valueRow(name: "Release Year", + value: String(UIDevice.current.generation), + icon: nil, + showMenu: true)) deviceSection.rows.append(valueRow(name: "UDID", value: UIDevice.current.identifierForVendor?.uuidString, icon: nil, showMenu: true)) + // Setup Application Section var applicationSection: Section = Section() applicationSection.title = "Application" - applicationSection.rows.append(valueRow(name: "Bundle Identifier", + applicationSection.rows.append(valueRow(name: "Bundle ID", value: Bundle.main.bundleIdentifier, icon: nil)) + if let value = Bundle.main.seedId { + applicationSection.rows.append(valueRow(name: "App ID Prefix", + value: Bundle.main.bundleIdentifier, + icon: nil)) + } applicationSection.rows.append(valueRow(name: "Version", value: Bundle.main.versionNumber, icon: nil))