-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProvisioningProfileParser.swift
68 lines (57 loc) · 3.55 KB
/
ProvisioningProfileParser.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// ProvisioningProfileParser.swift
// Mapsv2
//
// Created by Andrew Goodwin on 6/28/16.
// Copyright © 2016 Conway Corporation. All rights reserved.
//
import Foundation
class ProvisioningProfileParser: NSObject{
init(success:(() -> ())?){
super.init()
DispatchQueue.global().async {
guard let url = Bundle.main.url(forResource: "embedded", withExtension: "mobileprovision"), let data = try? Data(contentsOf: url), let string = String(data: data, encoding: String.Encoding.isoLatin1) else {
ProvisioningProfile.shared.isDebug = true
DispatchQueue.main.async {
success?()
}
return
}
let scanner = Scanner(string: string)
if scanner.scanUpTo("<plist", into: nil) {
var plistString:NSString? = ""
if scanner.scanUpTo("</plist>", into: &plistString) {
plistString = (plistString! as String) + "</plist>" as NSString
if let plistData = plistString?.data(using: String.Encoding.isoLatin1.rawValue) {
if let mobileProvision = try? PropertyListSerialization.propertyList(from: plistData, options: [], format: nil) as! [String:Any] {
ProvisioningProfile.shared.appName = mobileProvision["AppIDName"] as! String
ProvisioningProfile.shared.creationDate = mobileProvision["CreationDate"] as! Date
ProvisioningProfile.shared.expirationDate = mobileProvision["ExpirationDate"] as! Date
let entitlements = mobileProvision["Entitlements"] as! [String:Any]
if let debug = entitlements["get-task-allow"] as? Bool{
ProvisioningProfile.shared.isDebug = debug
}
ProvisioningProfile.shared.appId = entitlements["application-identifier"] as! String
ProvisioningProfile.shared.teamId = entitlements["com.apple.developer.team-identifier"] as! String
ProvisioningProfile.shared.teamName = mobileProvision["TeamName"] as! String
ProvisioningProfile.shared.ttl = mobileProvision["TimeToLive"] as! Int
ProvisioningProfile.shared.name = mobileProvision["Name"] as! String
if let certData = mobileProvision["DeveloperCertificates"] as? [Data] {
var certificateNames = [String]()
for data in certData {
let certificate:SecCertificate = SecCertificateCreateWithData(nil, data as CFData)!
let description:CFString = SecCertificateCopySubjectSummary(certificate)!
certificateNames.append(description as String)
}
ProvisioningProfile.shared.certificateNames = certificateNames
}
DispatchQueue.main.async {
success?()
}
}
}
}
}
}
}
}