Hi,
I'm trying to attach a CSV file to an email.
The code I have is below:
Code:
if ([mailClass canSendMail])
{
MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject:subject];
[email setMessageBody:body isHTML:isHTML];
if (attachment)
{
if ([attachment isKindOfClass:[NSString class]])
{
NSString *csvFile = (NSString *)attachment;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *thePath = [NSString stringWithFormat:@"%@/valuetable.csv", [paths objectAtIndex:0]];
[csvFile writeToFile:thePath atomically:NO encoding:NSStringEncodingConversionAllowLossy error:NULL];
NSData *attachmentData = [NSData dataWithContentsOfFile:thePath];
[email addAttachmentData:attachmentData mimeType:@"text/csv" fileName:@"Values"];
[[NSFileManager defaultManager] removeItemAtPath:thePath error:NULL];
}
}
[email setModalPresentationStyle:UIModalPresentationPageSheet];
[email.navigationBar setBarStyle:UIBarStyleBlackOpaque];
[self changeKeyboardToNormal:nil];
[self presentModalViewController:email animated:YES];
[email release];
}
The adding attachment code is definitely being called, and the attachmentData object is initialized properly. When I attach an NSData object containing a UIImage, it works. But when using a CSV file, the modal view controller doesn't present itself. Any explanations?
Thanks for any suggestions!
EDIT: Sorry, careless mistake! I was presenting the modal view controller from another modal view controller.