Is there a recommended way of testing for CSS file type in iOS?
I am asking for the NSURLTypeIdentifierKey thus:
NSError *err = nil;
NSString *uti = nil;
NSURL *fileURL = [NSURL fileURLWithPath:path];
[fileURL getResourceValue:&uti forKey:NSURLTypeIdentifierKey error:&err];
This works for most filetypes that I’ve tried it on, and I get back one of the Uniform Type Identifiers listed in the System-Declared Uniform Type Identifiers reference. I can test for RTF, etc, like this.
I noticed that for a CSS file I get back a UTI of “dyn.ah62d4rv4ge80g65x” though. I thought perhaps my CSS file had some odd metadata, so I cut and paste its contents into a brand new file in VI, and the UTI for that file came back the same.
I then did “cat /dev/null > empty.css” and tested the UTI of that empty file and it too came back with “dyn.ah62d4rv4ge80g65x”, so clearly this UTI is being derived from the file extension.
I don’t see any mention of “dyn…” UTIs in the reference. Can I rely on this odd string?
Usually this indicates a dynamic UTI, that is one that the system creates on the fly as it is not part of its database. In such case you probably have to examine other attributes like file extension or look inside the file.