Unable to either attach or create a .csv file (using CHCSVParser)
I am having a problem either attaching or creating a .csv file in my app,
I cannot figure out where the problem exists. In the email view the .csv
attachment is shown but when the email is received it has no attachment. I
send an array of objects (dataController.masterList) to the CHCSVWriter.
I've spent a lot of time this week trying solutions from other questions
regarding email attachments and CHCSVWriter and obviously none of the
solutions have worked so know I'm asking you. Thank you in advance, Happy
Days, -Rob
- (IBAction)send:(id)sender {
static NSDateFormatter *formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
NSString *filepath = @"testfile.csv";
filepath = [filepath stringByExpandingTildeInPath];
NSOutputStream *exportStream = [NSOutputStream
outputStreamToFileAtPath:filepath append:NO];
NSStringEncoding encodingA = NSUTF8StringEncoding;
CHCSVWriter *csvWriter = [[CHCSVWriter alloc]
initWithOutputStream:exportStream encoding:encodingA delimiter:','];
[csvWriter writeField:[NSString stringWithFormat:@"One"]];
[csvWriter writeLineOfFields:dataController.masterList];
[csvWriter closeStream];
NSString *path = [[NSBundle mainBundle] pathForResource:filepath
ofType:@".csv"];
NSData *mydata = [NSData dataWithContentsOfFile:path];
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController
alloc] init];
[mail setMailComposeDelegate:self];
[mail setSubject:@"CSV File"];
[mail addAttachmentData:mydata mimeType:@"text/csv" fileName:filepath];
[mail setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:mail animated:YES completion:nil];
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
No comments:
Post a Comment