Kenny Wyland
Kenny Wyland

Reputation: 21890

Standard UTType for Word Docs with UIDocumentPickerViewController?

I'm updating some old code to avoid deprecated stuff and to use new APIs with UIDocumentPickerViewController. I used to have to list a bunch of custom strings for various file types like so:

NSArray<NSString*> *types = @[
    (__bridge NSString *)kUTTypePDF,
    (__bridge NSString *)kUTTypeText,
    
    @"com.microsoft.word.doc",
    @"org.openxmlformats.wordprocessingml.document",
    
    @"com.microsoft.excel.xls",
    @"org.openxmlformats.spreadsheetml.sheet",
    
    @"com.microsoft.powerpoint.ppt",
    @"org.openxmlformats.presentationml.presentation",
    
    @"com.apple.iwork.pages.sffpages",
    @"com.apple.iwork.numbers.sffnumbers",
    @"com.apple.keynote.key",
    
    @"public.zip-archive",
];

UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:types inMode:UIDocumentPickerModeImport];

But I want to use the newer -initForOpeningContentTypes and use UTType which has many more built-in types that also cover lots of forms of those types. For example, instead of having to declare com.microsoft.excel.xls and org.openxmlformats.spreadsheetml.sheet in order to cover xls and xlsx files, I can just declare:

NSArray<UTType*> *types = @[
    UTTypePDF,
    UTTypeText,
    UTTypePresentation,
    UTTypeSpreadsheet,
    UTTypeZIP,
    [UTType typeWithIdentifier:@"com.microsoft.word.doc"],
    [UTType typeWithIdentifier:@"org.openxmlformats.wordprocessingml.document"],
    [UTType typeWithIdentifier:@"com.apple.iwork.pages.sffpages"],
];

UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:types asCopy:YES];

However, I cannot find a built-in UTType that will cover "word processing documents" like doc, docx, and pages. As far as I can tell, I still need to use raw string constants for those, but I'm hoping there is a built-in type I can use and maybe I'm just missing it in the documentation.

Is there a word-processing doc UTType that covers doc, docx, pages, etc, similar to how UTTypeSpreadsheet covers xls, xlsx, numbers, etc?

Upvotes: 1

Views: 357

Answers (1)

Sweeper
Sweeper

Reputation: 274780

No, there are no common identifiers among the word processing file formats, except the very general public.item, public.content etc.

You can view the UTType "tree" using the mdls command. These are the results for .doc, .docx, .pages:

% mdls -name kMDItemContentTypeTree foo.pages
kMDItemContentTypeTree = (
    "com.apple.iwork.pages.sffpages",
    "public.data",
    "public.item",
    "public.composite-content",
    "public.content"
)
% mdls -name kMDItemContentTypeTree foo.docx
kMDItemContentTypeTree = (
    "org.openxmlformats.wordprocessingml.document",
    "org.openxmlformats.openxml",
    "public.data",
    "public.item",
    "public.composite-content",
    "public.content"
)
% mdls -name kMDItemContentTypeTree foo.doc
kMDItemContentTypeTree = (
    "com.microsoft.word.doc",
    "public.data",
    "public.item",
    "public.composite-content",
    "public.content"
)

Spreadsheets on the other hand, have public.spreadsheet in common:

% mdls -name kMDItemContentTypeTree foo.numbers 
kMDItemContentTypeTree = (
    "com.apple.iwork.numbers.sffnumbers",
    "public.data",
    "public.item",
    "public.composite-content",
    "public.content",
    "public.spreadsheet"
)
% mdls -name kMDItemContentTypeTree foo.xlsx 
kMDItemContentTypeTree = (
    "org.openxmlformats.spreadsheetml.sheet",
    "org.openxmlformats.openxml",
    "public.data",
    "public.item",
    "public.composite-content",
    "public.content",
    "public.spreadsheet"
)

Upvotes: 1

Related Questions