tags:

views:

16

answers:

1

I'd like to introduce a feature in my iPhone App that allows the following: 1) creating and sending by email a CSV file from within my iPhone App. 2) importing into my iPhone App a CSV file created with 3rd party software and sent to me by email.

These are the questions: 1a) Is it possible to actually create a CSV file from within the App and send it as an attachment? I know I can send an email containing all the strings required, but I want to be able to send the actual file. 1b) Once created, can this file be stored into the memory allocated to my iPhone App? 2) What procedure should I follow to import a CSV file into my App? I do not want to read the CSV file from a URL. Can all this be done with the iPhone or not??

Thanks!

+1  A: 

1a) Yes, you can use the addAttachmentData:mimeType:fileName: method on an instance of the MFMailComposeViewController class to do that.

1b) Yes, you can write the NSString containing the CSV data to a file using the writeToFile:atomically:encoding:error: method.

2) Yes, in iOS 4 you can subscribe your app to certain file types, go here for more detailed information.

Douwe Maan
Thanks for the tip. I've managed to send text (.txt) attachments using the addAttachmentData method you suggested, however I am unable to attach CSV files (see code below). An icon appears in the mail application indicating a textfile.csv attachment but when the message arrives there is no attachment at all (neither the data appears in the message body). I've tried changing mime type to text/plain but it does not work.
There is no space here to add the code!!