This topic is mostly about iOS although it may apply to OS X as well.
I've placed a declaration in my app's UTImportedTypeDeclarations
saying that the .md
extension (among others) belong to UTI net.daringfireball.markdown
. This UTI is recommended by Markdown's initial author, hence is considered canonical.
Then I used UIDocumentPickerViewController
to open a Markdown file from Dropbox, indirectly using Dropbox's app extension. When creating that controller I specifically passed net.daringfireball.markdown
as one of the accepted UTIs.
To my surprise the returned UTI from that action was pro.writer.markdown
. Whereas my code was expecting net.daringfireball.markdown
to determine whether the file returned was indeed a Markdown file. To my app, pro.writer.markdown
wasn't recognized, and indeed it wasn't among the list of UTIs to be picked by UIDocumentPickerViewController
.
Upon further investigation, another app in my phone declares pro.writer.markdown
in its UTExportedTypeDeclarations
list. The app is iA Writer.
Now what would be the best way to get around this problem? These are what comes into my mind right now:
Admit defeat and add an "or" clause to the other UTI:
//...
else if(UTTypeConformsTo(fileUTI,@"net.daringfireball.markdown") || UTTypeConformsTo(fileUTI,@"pro.writer.markdown")) {
... // handle Markdown file
Fall back to the "superclass" UTI which is plain text:
//...
else if(UTTypeConformsTo(fileUTI,@"net.daringfireball.markdown") || UTTypeConformsTo(fileUTI,kUTTypePlainText)) {
... // handle Markdown file
The first one has the downside that I need to list down every other app's incorrect declaration of Markdown. The second one seems more plausible, but I wonder whether I am overlooking something?
Or is there a better alternative than these two?
One option is to check the file extension of the selected file.
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
NSString *fileUTI = ...
if ([url.pathExtension isEqualToString:@"md"] || UTTypeConformsTo(fileUTI, @"net.daringfireball.markdown")) {
}
}