11import SwiftUI
2+ import Security
23
34struct AppsView : View {
5+ @State private var certNames : [ String ] = [ ]
6+ @State private var errorMessage : String ?
7+
48 var body : some View {
5- Text ( " Placeholder " )
9+ VStack ( spacing: 20 ) {
10+ Text ( " Certificate Info " )
11+ . font ( . largeTitle)
12+ . bold ( )
13+
14+ if !certNames. isEmpty {
15+ ForEach ( certNames, id: \. self) { name in
16+ Text ( " • \( name) " )
17+ . font ( . title3)
18+ }
19+ } else if let error = errorMessage {
20+ Text ( error)
21+ . foregroundColor ( . red)
22+ } else {
23+ Text ( " Loading… " )
24+ }
25+ }
26+ . padding ( )
27+ . onAppear {
28+ loadCertificateNames ( )
29+ }
30+ }
31+
32+ func loadCertificateNames( ) {
33+ guard let provPath = Bundle . main. path ( forResource: " embedded " , ofType: " mobileprovision " ) ,
34+ let provData = try ? Data ( contentsOf: URL ( fileURLWithPath: provPath) ) ,
35+ let provString = String ( data: provData, encoding: . ascii) else {
36+ errorMessage = " No provisioning profile found. "
37+ return
38+ }
39+
40+ guard let start = provString. range ( of: " <?xml " ) ,
41+ let end = provString. range ( of: " </plist> " ) else {
42+ errorMessage = " Invalid provisioning profile structure. "
43+ return
44+ }
45+
46+ let plistString = String ( provString [ start. lowerBound... end. upperBound] )
47+
48+ guard let plistData = plistString. data ( using: . utf8) ,
49+ let plist = try ? PropertyListSerialization . propertyList ( from: plistData, options: [ ] , format: nil ) as? [ String : Any ] ,
50+ let devCerts = plist [ " DeveloperCertificates " ] as? [ Data ] else {
51+ errorMessage = " Couldn't read DeveloperCertificates. "
52+ return
53+ }
54+
55+ var names : [ String ] = [ ]
56+
57+ for certData in devCerts {
58+ if let cert = SecCertificateCreateWithData ( nil , certData as CFData ) ,
59+ let summary = SecCertificateCopySubjectSummary ( cert) as String ? {
60+ names. append ( summary)
61+ }
62+ }
63+
64+ if names. isEmpty {
65+ errorMessage = " No certificate names found. "
66+ } else {
67+ certNames = names
68+ }
669 }
7- }
70+ }
0 commit comments