Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a document UTI from a file path?

I have a document path as an NSString. How do I get its UTI as an NSString? I currently use LSCopyItemAttribute but that requires an FSRef and all the functions for making an FSRef seems to be deprecated.

(Note: This is for Mac OS 10.8+.)

like image 215
Mike T Avatar asked Dec 16 '25 18:12

Mike T


1 Answers

You will be able to get it using mobile core services framework. Refer the code below

NSString *path; // contains the file path

// Get the UTI from the file's extension:

CFStringRef pathExtension = (__bridge_retained CFStringRef)[path pathExtension];
CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
CFRelease(pathExtension);

The code snippet is taken from here.

like image 154
Vignesh Avatar answered Dec 19 '25 09:12

Vignesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!