I am building a viewer application, which needs to accept "any" kind of file as the selected file to view. In fact it even should accept folders, because in that case I want to show information relevant about the folder such as number of files and such.
Now suppose I decided to use the NSDocument
based application architecture to do this. How do I make my application accept any kind of file (and not get these [NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]
failed messages?
Based on the discussion: iOS Document/File type associations - wildcard UTI? I managed to get it working (it seems):
Name
property to public.item
.Now the application will be able to open any kind of file as its document. One thing to remember is to keep the following (automatically generated during project creation) methods in place. I deleted them, assuming I did not need them, and that created another error:
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
and to be able to have folders as your document, add:
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
It seems to work for now, any additional remarks are welcome.