What to do with CSV after export on the iPhone?
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: How to convert data to CSV or HTML format on iOS?
What I'm wondering about is what I can do with the file开发者_Python百科 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?
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.
Usually when an iPhone app needs exporting functionality you have the following options:
- Attaching it to an email (as you mentioned)
- Sending it to a server (with HTTP or any other TCP/IP based protocol)
- 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.
精彩评论