Question

I'm working on an iOS app that allows the user to send to store (using core data) and send back data in the form of a csv file which i have attached to an email using the MFMailComposeViewController class.

After the file is sent I want to iterate through the data and set a submitted flag on each record so its not sent again when the user hits the button to submit more data

This is easy to do - I can call the method to do that from within

    -(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{

Using

    case MFMailComposeResultSent:

I would like to clean up after myself and also delete the csv file after it is sent but my problem is this.... (edit - see EDIT AFTER MORE TESTS at bottom)

MFMailComposeResultsSent is the MFMailComposeResult both if the mail has been sent and also if its made it to the outbox and hasn't gone. If I delete the csv files at this point and the internet connection is down and the mail is in the outbox then when the connection is back up and the mail gets sent then the attached files have already been deleted and obviously don't get sent.

The size of my csv files are small - a single record weighing in at about 1kb, 5 at about 2kb (the difference because of a first line being all the field names) and on that basis it is unlikely that any files will ever be bigger than 30kb so i'll not be using lots of memory. Realistically I cant see any case where even the most enthusiatic of users generates more than half a MB of data

Any thoughts how i could/should approach this ? Im not sure what apples take on having a bunch of tiny files left around would be and how this might affect my app submission.

Thanks in advance for taking the time to read and/or respond to this

Simon

EDIT

There seems to be some issue with a time delay - perhaps iOS is caching the deleted files? for a brief time.

I had a bunch of test runs where the attachments went thru - i've been testing sending with wifi off and airplane mode on and the files went thru a short while after when i turned them back on. I just did i test where i left the wifi route on and i was still connected but pulled the cable from the back of the wifi router so i had no internet behind it By the time i went back to the router and plugged it in and the mail went , it had lost the attachment files and the mail went through without them. Now i have a bunch of tests half where the attachments went through and half where they didn't

EDIT AFTER MORE TESTS

My question may have been spurred by my misunderstanding of what was happening when - but I haven't marked the question as answered as I would still like to know if its possible to check it the mail has actually gone. One supplied answer say No its not possible - can anyone else confirm this then I'll mark that as the answer.

Anyway

I think my problem with the losing the attachments may have come from going into the mail app and checking the outbox while mail was failing to find a connection. Sometimes Mail will add a warning side on the mail and the attachments will disappear sometimes. If i leave the outbox well alone the attachments seem to go as they should. I'm going to do more testing on this to confirm this is actually the case.

Was it helpful?

Solution

Unfortunately there is no way to check that.

MFMailComposeResultSent

The email message was queued in the user’s outbox. It is ready to send the next time the user connects to email.

Means this result will get when the message is queued for sending (still in outbox), there is no result will be generated after it is sent.

Please MFMailComposeViewController for details.

OTHER TIPS

How are you attaching the CSV files to the email? Instead of specifying a file URL, you could try attaching the NSData. That way your attachment isn't tied to an external file, but is embedded within the email itself.

Look at MFMailComposeViewController addAttachmentData for more details.

e.g.

NSData *csvData = [NSData dataWithContentsOfFile:filePath];

Attach csvData to your MFMailComposeViewController using addAttachmentData.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top