Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed MacOS Sequoia provisioning profiles path #267

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions ProvisioningProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,43 @@ struct ProvisioningProfile {
fileprivate let delegate = NSApplication.shared.delegate as! AppDelegate

static func getProfiles() -> [ProvisioningProfile] {
var output: [ProvisioningProfile] = []

let fileManager = FileManager()
if let libraryDirectory = fileManager.urls(for: .libraryDirectory, in: .userDomainMask).first {
let provisioningProfilesPath = libraryDirectory.path.stringByAppendingPathComponent("MobileDevice/Provisioning Profiles") as NSString
if let provisioningProfiles = try? fileManager.contentsOfDirectory(atPath: provisioningProfilesPath as String) {

for provFile in provisioningProfiles {
if provFile.pathExtension == "mobileprovision" {
let profileFilename = provisioningProfilesPath.appendingPathComponent(provFile)
if let profile = ProvisioningProfile(filename: profileFilename) {
output.append(profile)
}
}
}
}
}

// distinct
output = output.sorted(by: {
$0.created.timeIntervalSince1970 > $1.created.timeIntervalSince1970
})

guard let libraryDirectory = fileManager.urls(for: .libraryDirectory, in: .userDomainMask).first else { return [] }

var newProfiles = [ProvisioningProfile]()
var names = [String]()
for profile in output {
if !names.contains("\(profile.name)\(profile.appID)") {
newProfiles.append(profile)
names.append("\(profile.name)\(profile.appID)")
let preMacOSSequouiaPath = libraryDirectory
.path
.stringByAppendingPathComponent("MobileDevice/Provisioning Profiles")

let macOSSequoiaPath = libraryDirectory
.path
.stringByAppendingPathComponent("Developer/Xcode/UserData/Provisioning Profiles")

let profiles = [preMacOSSequouiaPath, macOSSequoiaPath]
.flatMap { (profilesPath: String) -> [String] in
let contents = (try? fileManager.contentsOfDirectory(atPath: profilesPath)) ?? []
return contents.map { (profile: String) -> String in
profilesPath.stringByAppendingPathComponent(profile)
}
}
.filter { path in
path.pathExtension == "mobileprovision"
}
.compactMap { path in
ProvisioningProfile(filename: path)
}
.sorted { lhs, rhs in
lhs.created.timeIntervalSince1970 > rhs.created.timeIntervalSince1970
}

var names = Set<String>()
return profiles.filter { profile in
let inserted = names.insert("\(profile.name)\(profile.appID)").inserted
if inserted {
NSLog("\(profile.name), \(profile.created)")
}
return inserted
}
return newProfiles;
}

init?(filename: String){
Expand Down
Loading