Skip to content

Instantly share code, notes, and snippets.

@acalism
Created February 27, 2018 07:32
Show Gist options
  • Save acalism/58a0a582d57fbd53d5d0b9352c6c6566 to your computer and use it in GitHub Desktop.
Save acalism/58a0a582d57fbd53d5d0b9352c6c6566 to your computer and use it in GitHub Desktop.
What is a live photo file?
import Foundation
import MobileCoreServices
if let t = UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension, "mp4" as CFString, nil)?.takeRetainedValue() as? [CFString] {
print(t)
print(UTTypeConformsTo(t[0], kUTTypeMovie), "\n")
}
if let t = UTTypeCreateAllIdentifiersForTag(kUTTagClassMIMEType, "application/json" as CFString, nil)?.takeRetainedValue() as? [CFString] {
print(t)
print(UTTypeConformsTo(t[0], kUTTypeText), "\n")
}
if let t = UTTypeCopyPreferredTagWithClass(kUTTypeJPEG, kUTTagClassFilenameExtension)?.takeRetainedValue() {
print(t, "\n")
}
for uti in [kUTTypeJPEG, kUTTypeLivePhoto, kUTTypeMPEG, kUTTypeMPEG4, kUTTypePDF, kUTTypeJSON] {
if let d = UTTypeCopyDescription(uti)?.takeRetainedValue() {
print(d)
}
if let d = UTTypeCopyDeclaration(uti)?.takeRetainedValue() as? [String : Any] {
print(d)
}
print()
}
// kUTTypeLivePhoto has no file extension, and conforms to nobody
// https://stackoverflow.com/questions/32508375/apple-live-photo-file-format
// It contains both a JPEG and a quicktime MOV
print(UTTypeConformsTo(kUTTypeLivePhoto, kUTTypeImage)) // false
@acalism
Copy link
Author

acalism commented Mar 2, 2018

关于 UTI(Uniform Type Identifiers),还有一篇文章的介绍比官方更好,
https://arstechnica.com/gadgets/2005/04/macosx-10-4/11/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment