@@ -13,6 +13,7 @@ class BuildDetails {
1313 static var `default` = BuildDetails ( )
1414
1515 let dict : [ String : Any ]
16+ private var cachedProfileExpirationDate : Date ?
1617
1718 init ( ) {
1819 guard let url = Bundle . main. url ( forResource: " BuildDetails " , withExtension: " .plist " ) ,
@@ -23,6 +24,7 @@ class BuildDetails {
2324 return
2425 }
2526 dict = parsed
27+ cachedProfileExpirationDate = loadProfileExpirationDate ( )
2628 }
2729
2830 var buildDateString : String ? {
@@ -46,11 +48,11 @@ class BuildDetails {
4648 }
4749
4850 var profileExpiration : Date ? {
49- return dict [ " com-loopkit-Loop-profile-expiration " ] as? Date
51+ return cachedProfileExpirationDate
5052 }
5153
5254 var profileExpirationString : String {
53- if let profileExpiration = profileExpiration {
55+ if let profileExpiration = cachedProfileExpirationDate {
5456 return " \( profileExpiration) "
5557 } else {
5658 return " N/A "
@@ -65,5 +67,39 @@ class BuildDetails {
6567 var workspaceGitBranch : String ? {
6668 return dict [ " com-loopkit-LoopWorkspace-git-branch " ] as? String
6769 }
70+
71+ private func loadProfileExpirationDate( ) -> Date ? {
72+ guard
73+ let profilePath = Bundle . main. path ( forResource: " embedded " , ofType: " mobileprovision " ) ,
74+ let profileData = try ? Data ( contentsOf: URL ( fileURLWithPath: profilePath) ) ,
75+ let profileNSString = NSString ( data: profileData, encoding: String . Encoding. ascii. rawValue)
76+ else {
77+ print (
78+ " WARNING: Could not find or read `embedded.mobileprovision`. If running on Simulator, there are no provisioning profiles. "
79+ )
80+ return nil
81+ }
82+
83+ let regexPattern = " <key>ExpirationDate</key>[ \\ W]*?<date>(.*?)</date> "
84+ guard let regex = try ? NSRegularExpression ( pattern: regexPattern, options: [ ] ) ,
85+ let match = regex. firstMatch (
86+ in: profileNSString as String ,
87+ options: [ ] ,
88+ range: NSRange ( location: 0 , length: profileNSString. length)
89+ ) ,
90+ let range = Range ( match. range ( at: 1 ) , in: profileNSString as String )
91+ else {
92+ print ( " Warning: Could not create regex or find match. " )
93+ return nil
94+ }
95+
96+ let dateString = String ( profileNSString. substring ( with: NSRange ( range, in: profileNSString as String ) ) )
97+ let dateFormatter = DateFormatter ( )
98+ dateFormatter. dateFormat = " yyyy-MM-dd'T'HH:mm:ss'Z' "
99+ dateFormatter. locale = Locale ( identifier: " en_US_POSIX " )
100+ dateFormatter. timeZone = TimeZone ( secondsFromGMT: 0 )
101+
102+ return dateFormatter. date ( from: dateString)
103+ }
68104}
69105
0 commit comments