66import Foundation
77
88public extension ProcessInfo {
9+ var hasTXMClassic : Bool {
10+ ProcessInfo . processInfo. isiOSAppOnMac ? false : ProcessInfo . detectLocalTXM ( )
11+ }
12+
913 var hasTXM : Bool {
1014 if isTXMOverridden {
1115 return true
1216 }
1317
1418 return ProcessInfo . hasTXMSupport (
15- operatingSystemVersion: operatingSystemVersion,
16- localTXMDetector: ProcessInfo . detectLocalTXM
19+ isIOS266OrNewer: ProcessInfo . isIOS266OrNewer,
20+ hasTXMClassic: hasTXMClassic,
21+ hardwareIdentifier: hardwareIdentifier ( )
1722 )
1823 }
1924
2025 var isTXMOverridden : Bool {
2126 UserDefaults . standard. bool ( forKey: UserDefaults . Keys. txmOverride)
2227 }
2328
24- static func hasTXMSupport(
25- operatingSystemVersion: OperatingSystemVersion ,
26- localTXMDetector: ( ) -> Bool
29+ internal static func hasTXMSupport(
30+ isIOS266OrNewer: Bool ,
31+ hasTXMClassic: Bool ,
32+ hardwareIdentifier: String
2733 ) -> Bool {
28- guard operatingSystemVersion. majorVersion >= 26 else {
34+ if isIOS266OrNewer, !hasTXMClassic {
35+ let firstTXM = 14.2
36+ let iPadTXM = 14.5
37+
38+ if let ver = ProcessInfo . processInfo. deviceVersion ( from: hardwareIdentifier) {
39+ if hardwareIdentifier. hasPrefix ( " iPad " ) {
40+ return ver >= iPadTXM
41+ } else {
42+ return ver >= firstTXM
43+ }
44+ }
45+
2946 return false
3047 }
31- return localTXMDetector ( )
48+
49+ return hasTXMClassic
50+ }
51+
52+ func deviceVersion( from identifier: String ) -> Double ? {
53+ let iPhonePattern = #"iPhone(\d+),(\d+)"#
54+ let iPadPattern = #"iPad(\d+),(\d+)"#
55+
56+ let extractVersion : ( _ pattern: String ) -> Double ? = { pattern in
57+ guard let regex = try ? NSRegularExpression ( pattern: pattern) ,
58+ let match = regex. firstMatch (
59+ in: identifier,
60+ range: NSRange ( identifier. startIndex... , in: identifier)
61+ ) ,
62+ let majorRange = Range ( match. range ( at: 1 ) , in: identifier) ,
63+ let minorRange = Range ( match. range ( at: 2 ) , in: identifier) ,
64+ let major = Double ( identifier [ majorRange] ) ,
65+ let minor = Double ( identifier [ minorRange] )
66+ else {
67+ return nil
68+ }
69+
70+ let divisor = pow ( 10.0 , Double ( String ( Int ( minor) ) . count) )
71+ return major + ( minor / divisor)
72+ }
73+
74+ return extractVersion ( iPhonePattern) ?? extractVersion ( iPadPattern)
3275 }
3376
3477 private static func detectLocalTXM( ) -> Bool {
@@ -41,4 +84,23 @@ public extension ProcessInfo {
4184 access ( " \( $0) /usr/standalone/firmware/FUD/Ap,TrustedExecutionMonitor.img4 " , F_OK) == 0
4285 } ?? false
4386 }
87+
88+ private static var isIOS266OrNewer : Bool {
89+ if #available( iOS 26 . 6 , * ) {
90+ return true
91+ }
92+
93+ return false
94+ }
95+
96+ private func hardwareIdentifier( ) -> String {
97+ var systemInfo = utsname ( )
98+ uname ( & systemInfo)
99+
100+ return withUnsafePointer ( to: & systemInfo. machine) {
101+ $0. withMemoryRebound ( to: CChar . self, capacity: 1 ) {
102+ String ( cString: $0)
103+ }
104+ }
105+ }
44106}
0 commit comments