// This implementation file shows how to extract details for the provisioning profile // but also demonstrates how to grab the certificate info from the DeveloperCertificates // arry found in the plist 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 { return } // Extract the relevant part of the data string from the start of the opening plist tag // to the ending one. let scanner = Scanner(string: string) if scanner.scanUpTo("", into: &plistString) { plistString = (plistString! as String) + "" as NSString if let plistData = plistString?.data(using: String.Encoding.isoLatin1.rawValue) { // Load the property list into a dictionary if let mobileProvision = try? PropertyListSerialization.propertyList(from: plistData, options: [], format: nil) as? [String:Any] { // Grab all of the profile properties let appName = mobileProvision["AppIDName"] as! String let creationDate = mobileProvision["CreationDate"] as! Date let expirationDate = mobileProvision["ExpirationDate"] as! Date let teamName = mobileProvision["TeamName"] as! String let ttl = mobileProvision["TimeToLive"] as! Int let name = mobileProvision["Name"] as! String // Grab the nested entitlements dictionary and relevant properties let entitlements = mobileProvision["Entitlements"] as! [String:Any] var taskAllow = entitlements["get-task-allow"] as? Bool ?? false let appId = entitlements["application-identifier"] as! String let teamId = entitlements["com.apple.developer.team-identifier"] as! String // Iterate through the DeveloperCertificates array sorted by notValidAfter date // (see Comparable implementation in the SecCertificateWrapper.swift file) and // create and print SecCertificateWrapper objects if let certData = mobileProvision["DeveloperCertificates"] as? [Data] { for cert in certData.map( { SecCertificateWrapper(data: $0) }).sorted() { debugPrint("Name: \(cert.name), Not Valid After Date: \(cert.notValidAfterUnixDateAsString)") } } } } } }