Sending a text file to an iOS app

Friends

I need to send a text file of CSV data to my iOS app.

I cannot find any example code for how to do it, and I am stumped.

I imagining the user will be on a device that can send the file to my iOS app using Air Drop.

I have seen a lot of partial information about:

  • UIActivityViewController: I am using this to go in the opposite direction. Getting a PDF file generated in my app off the iPad
  • UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace. This suggests that if I set these to true in info.plist then my apps document directory will show up in the files app. Not as far as I can tell. Perhaps I am doing it wrong?

Answering my own question, with another:

I added the following to the info.plist file:

	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeName</key>
			<string>Draft Layouts</string>
			<key>LSHandlerRank</key>
			<string>Owner</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>public.comma-separated-values-text</string>
			</array>
		</dict>
	</array>

and

	<key>LSApplicationCategoryType</key>
	<string></string>

and

	<key>LSSupportsOpeningDocumentsInPlace</key>
	<true/>

Now when I use AirDrop to drop a CSV file on the iPad my app is listed as a recipient.

Inspecting the bundle I see it is placed in:

AppData/Documents/Inbox/MyFile.csv

I am unsure what changes I made to info.plist are necessary, or quite what they are for.

Have I set a trap for myself? I do not know.....

So it works now ? Great. Don't forget to close the thread if that's the case.

You can also do it manually from the Mac:

To transfer original file from Mac to iPhone/iPad:

  • connect the iPhone/iPad with USB
  • Open any folder on the Mac
  • Select your iPhone/iPad on the left pane of the window,
  • Select Files tab
  • Drag and drop the original pdf file onto ‘my app’ folder

Or you can send with AirDrop and save in Files. From there you will be able to access from the app.

Or you can send with AirDrop and save in Files. From there you will be able to access from the app.

It depends on the settings in Info.plist

Where are they documented?

I am especially concerned that I cannot find public.comma-separated-values-text documented anywhere.

I have this working, with that above and below, for CSV, but I also need JSON. Without any documentation of these settings it is very difficult.

Currently the relevant parts are

	<key>CFBundleDisplayName</key>
	<string>My App Name</string>
	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeName</key>
			<string>My App Files</string>
			<key>LSHandlerRank</key>
			<string>Owner</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>public.comma-separated-values-text</string>
			</array>
		</dict>
	</array>

There must be documentation some place.

Can I just add JSON support with:

			<array>
				<string>public.comma-separated-values-text</string>
				<string>public.json</string>
			</array>
Sending a text file to an iOS app
 
 
Q