So for a while I have been build a survey for people to complete on their i-phones all the data is saved to a csv file then sent in a email via the app once complete... however im having trouble attaching the csv file! Let me explain.
My code was as follows:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setToRecipients:@[@"gpsflighttrial@gcap.eu"]];
[mailer setSubject:self.subject.text];
[mailer setMessageBody:self.message.text isHTML:NO];
[mailer addAttachmentData:[NSData dataWithContentsOfFile:@"results.csv"]
mimeType:@"application/csv"
fileName:@"results.csv"];
[self presentModalViewController:mailer animated:YES];
This would attach the csv file within the app and send it however upon receiving it the csv file would have disappeared (As if by magic!) to check the file was correct etc and saving the data it add the actual log so it looked like this:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setToRecipients:@[@"gpsflighttrial@gcap.eu"]];
[mailer setSubject:self.subject.text];
[mailer setMessageBody:self.message.text isHTML:NO];
[mailer addAttachmentData:[NSData dataWithContentsOfFile:@"/var/mobile/Applications/CD2A1913-DEE0-41DD-9F8A-00DD6793F565/Documents/results.csv"]
mimeType:@"application/csv"
fileName:@"results.csv"];
[self presentModalViewController:mailer animated:YES];
SUCCESS! I thought as the email was sent within the app and the attachment was there upon receiving it! However when trying it on another phone bam back to the same thing attachment is there but upon receiving it there was no atahcment to be seen. I checked the log again only to find this time the other phone was saving it /var/mobile/Applications/B866A8EC-3A50-4642-B09B-F7DB15C66433/Documents/results.csv hence why it wasnt finding the attachment!
My question is how can i get around this? Is there a generic path name for the i-phone? How can i get the app to find the file on everyones phone when its saved in a different folder?
Thank you for your time :)