views:

133

answers:

2

One of the requested features for my apps is to have an export feature. Most of the time the data is table-like in nature. As an example, users might enter every day what types of food they ate that day, and how many portions of each food type. As the data is table-like, I figure the most useful for export would be into CSV format. Then it can be read in spreadsheet software.

I'm confident I can get the data into a CSV like format without too much trouble, and found this post would should help me: http://stackoverflow.com/questions/1512883/how-to-convert-data-to-csv-or-html-format

What I'm wondering about is what I can do with the file once it has been created? Can I attach it to an email? How else can I make it available to the user so that it has some use?

Alternatively, am I going about this the wrong way and would there be a better way to offer an export function?

A: 

Usually when an iPhone app needs exporting functionality you have the following options:

  1. Attaching it to an email (as you mentioned)
  2. Sending it to a server (with HTTP or any other TCP/IP based protocol)
  3. Exposing it with a small WebServer you code inside your app (like the Video Camera APPs for 3G and older iPhones do)

Unfortunately, you can't use iTunes for sync your exported file. At least you can't with the current version of the SDK.

Instead of CSV, I would use XML. It can also be read with Excel (or any other spreadsheet), plus you won't have to deal with COMMA (or any other separator for that matter) escaping.

Pablo Santa Cruz
Presumably if I was to send it to a server, this would probably be my server, and I would then email the users a link? And what is the benefit to exposing it to a webserver inside my app? It sounds like attaching to an email is the best option for me, do you happen to have any sample code? Finally, in regards to XML, that is true, but you do lose the advantage of being able to double-click to open in spreadsheet software. I'm not sure what percentage of users would know what to do with an XML file.
alku83
True. Haven't though of the DOUBLE-CLICKING issue. I don't have sample code to send the file as an attachment... The benefit of exposing a WebServer inside your app is you can put the URL into a UILabel, then the user copies that URL into his/her browser and then he/she can download the file. I don't know if there is an advantage on doing that. I guess it will depend on your app's nature. I think it's pretty handy for the VIDEO CAM APPs I mentioned.
Pablo Santa Cruz
A: 

I would suggest using MFMailComposeViewController and attaching your CSV file to it. This has the benefit of allowing the user to forward to the file to multiple recipients, customize the email body etc. You can also insert HTML into the email body, so if the data isn't too large you could simply present a table of the information within the email itself.

To send an attachment follow the instructions here.

davbryn
Thanks, I think that's just what I was after.
alku83