Created
December 7, 2016 10:22
-
-
Save mike-neko/bdbedbb280883dff96b6a5a7062c67bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let url = Bundle.main.url(forResource: "embedded", withExtension: "mobileprovision") else { | |
return | |
} | |
guard let data = try? Data(contentsOf: url), | |
let start = "<?xml".data(using: .utf8), | |
let end = "</plist>".data(using: .utf8) | |
let startRange = data.range(of: start), | |
let endRange = data.range(of: end) else { | |
return | |
} | |
let range = Range(uncheckedBounds: (lower: startRange.lowerBound, upper: endRange.upperBound)) | |
let body = data.subdata(in: range) | |
guard let dic = try? PropertyListSerialization.propertyList(from: body, options: [], format: nil), | |
let plist = dic as? [String: Any], let expir = plist["ExpirationDate"] as? Date else { | |
return | |
} | |
let limit = Date(timeInterval: -24 * 60 * 60, since: expir) | |
let fmt = DateFormatter() | |
fmt.locale = Locale.current | |
fmt.timeZone = TimeZone.current | |
fmt.dateFormat = "yyyy/MM/dd" | |
print(fmt.string(from: limit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment