-->

How do you get the Finder “Kind” for a file, in 20

2019-05-19 22:54发布

问题:

This answer says to use LSCopyKindStringForURL(), which has worked great in the past, but it's marked "deprecated" in OS X v10.11.

There's no mention in the API documentation of why it was deprecated. I don't see any mention of Launch Services API changes in the OS X 10.11 release notes at all.

How are you supposed to get the Finder Kind of a file now?

回答1:

If you go to the declaration of LSCopyKindStringForURL() in the header (/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/LSInfoDeprecated.h), you'll find in the comment and the deprecation attribute, the following:

Use the URL resource property kCFURLLocalizedTypeDescriptionKey or NSURLLocalizedTypeDescriptionKey instead.

These are resource keys for use with CFURLCopyResourcePropertyForKey() or -[NSURL getResourceValue:forKey:error:], respectively.