Open In … All Files

Let’s say you are building an app that does some sort of file handling where you want to be able to open any and all file types in your app. When your app then launches it would do something with the file, like upload it to a server.

I was not quite certain how to achieve this effect myself, so I turned to Dropbox who are doing exactly that. If you have the Dropbox iOS app install you can open any file in Dropbox. Then you can choose where to put it in your online storage.

How did they do that? Did they register for a truckload of file types? Or is there a shortcut that I didn’t know about yet?

BSA Banner

Of course I didn’t ask any person at Dropbox directly. It was easier than that. All I needed was to download the dropbox app from the app store, rename the ipa to zip, uncompress it and dig into the bundle to find the info.plist. It’s binary, but double-clicking on it lets me view it in Xcode’s plist editor.

There we see how simple it can be. Dropbox.app only registers a single document type “All Files” with two UTIs.

You might remember back from my UTI article that a file type always needs to have two Universal Type Identifiers. One from the functional hierarchy and one from the physical hierarchy. An app will be shown in the “Open In” list if the UTI of the file in question conforms to the UTIs specified in the document types your app supports.

public.content is the root of the functional hierarchy and means “I don’t care about which function a file is for.”

public.data on the other hand is not the root node of the physical hierarchy. It stands for any flat file and thus excludes file bundles as you often see them used for file formats on Mac or iOS. I believe that Dropbox consciously excludes these because of the multi-platform nature of Dropbox. They don’t know the special tricks by which Apple makes you believe that you are dealing with a single file when you are actually working with a folder.

I didn’t take the time to test my assumption but I’m pretty sure that public.data precludes bundles. If you also want to include these then you can either add a second document type for “All File Bundles” with public.content + com.apple.package or you do a real wildcard definition by choosing the roots of both hierarchies: public.item + public.content.

The latter would also include directories and symlinks, but I don’t think you’ll ever see iOS trying to send you one of these.

Conclusion

By specifying a generic document type you can allow your app to open a wide variety of file formats. There is the rare occasion where you want to be able to be opened with all kinds of files and not only your specific custom document type. Now you know how to achieve that.