Support Opening CSV file in iOS app

This is a write-up about how to implement opening CSV file in my iOS app, Life Logger, so that users can import data by opening a CSV file from another app. It can be used as a reference for opening other types of files as well.

It is also an example of how lacking Apple’s documentation is.

The main steps are outlined in App Programming Guide for iOS, in the "Receiving Files and Data Sent to Your App" section, which is incredibly brief.

The article talks about adding a name and UTI for a Document Type entry, in the "Info tab of your Xcode project", which should have been "Info tab of your target settings". UTI is the most important as it specifies the file type to be supported, but the document didn't explain what it is nor did it explain that UTI should be entered in the "Types" field in Xcode. There are also no details or pointers about how to support specific file types. All it said was, "iOS uses the specified UTIs to determine if your app is eligible to open a given document".

To support CSV file, you need to enter CSV file in the Name field in the Document Type entry, and public.comma-separated-values-text in the Types field. The Name field value seems to be arbitrary and is just for your own reference.

Once you have done that, the app Info.plist will be updated with entries as described in this other Apple document, Registering the File Types Your App Supports. The "Types" field in Xcode corresponds to LSItemContentTypes in Info.plist.

Receiving Files and Data Sent to Your App should really have a link to Registering the File Types Your App Supports. But what's worse is that both documents do not provide pointers to reference that tells me which LSItemContentTypes values correspond to which file types.

One such reference for LSItemContentTypes is available in System-Declared Uniform Type Identifiers in Uniform Type Identifiers Reference. However it doesn’t contain CSV file format. And like the other Apple documents above, it is declared "no longer being updated" in the first section.

Another reference for LSItemContentTypes is available in MobileCoreServices Constants. This list finally has the value for CSV files. However, you will have to import MobileCoreServices framework in a project and print out kUTTypeCommaSeparatedText to figure out what the value is! I have confirmed that it is public.comma-separated-values-text.

Let’s summarise what we have learnt.

Apple, your documentation sucks!

And...

Hire me to fix it!

Reference

Apple docs marked as "no longer being updated":

Other Apple docs:

Support Opening CSV file in iOS app
Share this