Search code examples
iphoneattachmentmfmailcomposer

Mail attachments create problem


I want to create a csv file with ny string and attaching that. I were try this by using these lines

[foodString writeToFile:@"Meal.csv" atomically:YES encoding:NSUTF8StringEncoding error:NULL];
                [mailView addAttachmentData:NULL mimeType:@"text/csv" fileName:@"Meal.csv"];
                [mailView setMessageBody:@"Open attached file." isHTML:NO];

and MFMail shows me an icon of file in the mail but i couldn't get any file.

Please help me out.Thanx...


Solution

  • Clue ...

    addAttachmentData:NULL
    

    You need to actually attach the data. The filename is just the name you are choosing to give the file, it has no other use and doesn't mean attach the file with that name.

    The MFMailComposeViewController documentation makes it clear.

    You therefore need to do something like this;

    NSData *myData = [NSData dataWithContentsOfFile:your-full-file-path];
    

    To generate the data. Note you need to give the full filepath, not just the name (left as an exercise for the reader).