开发者

Implementing email with attachments

开发者 https://www.devze.com 2023-02-26 06:14 出处:网络
In my iPhone app, I have a view where I am showing the names of files stored in the Documents directory.

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:

  1. Can I attach more than one file, and if so, what is yhe maximum number of files that can be attached?
  2. 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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号