In my iPhone app, I have a view where I am showing the names of files stored in the Documents directory.
These开发者_C百科 files are downloaded from a server, and now I want to implement an email function into my application.
My questions are:
- Can I attach more than one file, and if so, what is yhe maximum number of files that can be attached?
- When I attach a file, do I have to give the location where it is stored?
Assuming you're using the stock MFMailComposeViewController, you can add more than one attachment using addAttachmentData:mimeType:fileName:
. You have to attach the raw data, so you'll need to fetch the file from disk and get an NSData
representation. Here's an example of how to add to add a UIImage
as an attachment:
MFMailComposeViewController *mvc = [[MFMailComposeViewController alloc] init];
mvc.mailComposeDelegate = self;
[mvc setSubject:@"My Subject"];
[mvc setMessageBody:@"My Message Body" isHTML:NO];
NSData *imageData = UIImageJPEGRepresentation(myImage, 1);
[mvc addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"image.jpg"];
[self presentModalViewController:mvc animated:YES];
[mvc release];
精彩评论