Skip to content

Instantly share code, notes, and snippets.

@mike-neko
Created December 7, 2016 10:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-neko/bdbedbb280883dff96b6a5a7062c67bd to your computer and use it in GitHub Desktop.
Save mike-neko/bdbedbb280883dff96b6a5a7062c67bd to your computer and use it in GitHub Desktop.
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