@@ -13,6 +13,7 @@ class BuildDetails {
13
13
static var `default` = BuildDetails ( )
14
14
15
15
let dict : [ String : Any ]
16
+ private var cachedProfileExpirationDate : Date ?
16
17
17
18
init ( ) {
18
19
guard let url = Bundle . main. url ( forResource: " BuildDetails " , withExtension: " .plist " ) ,
@@ -23,6 +24,7 @@ class BuildDetails {
23
24
return
24
25
}
25
26
dict = parsed
27
+ cachedProfileExpirationDate = loadProfileExpirationDate ( )
26
28
}
27
29
28
30
var buildDateString : String ? {
@@ -46,11 +48,11 @@ class BuildDetails {
46
48
}
47
49
48
50
var profileExpiration : Date ? {
49
- return dict [ " com-loopkit-Loop-profile-expiration " ] as? Date
51
+ return cachedProfileExpirationDate
50
52
}
51
53
52
54
var profileExpirationString : String {
53
- if let profileExpiration = profileExpiration {
55
+ if let profileExpiration = cachedProfileExpirationDate {
54
56
return " \( profileExpiration) "
55
57
} else {
56
58
return " N/A "
@@ -65,5 +67,39 @@ class BuildDetails {
65
67
var workspaceGitBranch : String ? {
66
68
return dict [ " com-loopkit-LoopWorkspace-git-branch " ] as? String
67
69
}
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
+ }
68
104
}
69
105
0 commit comments